Welcome Guest, Not a member yet? Register   Sign In
change the value of the array
#1

(This post was last modified: 05-11-2019, 03:03 PM by DELE.)

My Array :
PHP Code:
Array
(
 
   [0] => Array
 
       (
 
           [income_user] => 00002
            
[income_country] => 1CN,1US,1US,1ID
        
)

 
   [1] => Array
 
       (
 
           [income_user] => 00003
            
[income_country] => 2US
        
)

 
   [2] => Array
 
       (
 
           [income_user] => 00004
            
[income_country] => 1US
        
)


I want to change the value of each income_country:
PHP Code:
foreach ($data as $key => $value)
{
 
   foreach (explode(','$value["income_country"]) as $val)
 
   {
 
       preg_match('#([0-9]+)([A-Z]+)#',$val,$extrack);
 
       $a                $extrack[1];
 
       $b                $extrack[2];
 
       $c                isset($z[$b])?$z[$b]:0;
 
       $d                $c $a;
 
       $z[$b           $d;
 
       arsort($z);
 
   }
 
   $data[$key]["income_country"] = $z;


Results :
PHP Code:
Array
(
 
   [0] => Array
 
       (
 
           [income_user] => 00002
            
[income_country] => Array
 
               (
 
                   [US] => 2
                    
[CN] => 1
                    
[ID] => 1
                
)
 
       )

 
   [1] => Array
 
       (
 
           [income_user] => 00003
            
[income_country] => Array
 
               (
                    
// should [US] => 2

 
                   [US] => //?
 
                   [CN] => //?
 
                   [ID] => //?
 
               )
 
       )

 
   [2] => Array
 
       (
 
           [income_user] => 00004
            
[income_country] => Array
 
               (
 
                   // should [US] => 1

 
                   [US] => //?
 
                   [CN] => //?
 
                   [ID] => //?
 
               )
 
       )


why is the result always added to each array?
Reply


Messages In This Thread
change the value of the array - by DELE - 05-11-2019, 02:57 PM
RE: change the value of the array - by InsiteFX - 05-12-2019, 03:43 AM
RE: change the value of the array - by DELE - 05-12-2019, 07:51 AM
RE: change the value of the array - by DELE - 05-12-2019, 08:32 AM
RE: change the value of the array - by InsiteFX - 05-13-2019, 03:09 AM
RE: change the value of the array - by Wouter60 - 05-13-2019, 11:20 AM
RE: change the value of the array - by DELE - 05-14-2019, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB