0

Below is the display of my array $arr[0]. Could you please tell me how to take the values of inner array?

Here I need to take only the value for the ID 656 which is 'John'.

Array
(
    [0] => xxxxxxxxx
        (
            [Users] => Array
                (
                    [0] => Array
                        (
                            [name] => 656
                            [value] => John

                        )

                    [1] => Array
                        (
                            [name] => 657
                            [value] =>Peter

                        )

                    [2] => Array
                        (
                            [name] => 658
                            [value] => Louie

                        )

                    [3] => Array
                        (
                            [name] => 659
                            [value] => Jim

                        )



                )

        )

Thanks in advance.

3 Answers 3

1

try running a:

 foreach($arr as $key=>$value){
      var_dump($value);
 }

And you'll probably be able to work out what to do from there. Hope that helps?

EDIT: if

$arr = array(
       0=>array(
        'Users'=>array(
            0=>array('name'=>656, 'value'=>'John'), 
            1=>array('name'=>656, 'value'=>'John'), 
            2=>array('name'=>658, 'value'=>'Louie')
            )
        )

);

Then you can use:

foreach($arr as $Users){
    foreach($Users as $k=>$v){
        var_dump($v[0]['value']);
    }
}

To get 'John'. Does that help?

Sign up to request clarification or add additional context in comments.

Comments

1

If this isn't just a one-off, you could use a recursive array search function. If your data is in $arr, in the format you described:

$arr = array(array("Users"=>array(array("name"=>656,"value"=>"John"),array("name"=>657,"value"=>"Peter"))));

It might look like this:

print in_array_multi("656",$arr);
// ^-- This prints John

print in_array_multi("657",$arr);
// ^-- This prints Peter

function in_array_multi($item, $arr) {
    foreach ($arr as $key => $value) {
        if ($value==$item){
            return $arr['value'];
        } else if (is_array($value)){
            if($ret = in_array_multi($item, $value))
                 return $ret;
        }
    }
    return "";
}

Comments

0

for example:

i supose you have 3 arrays to arrive where you wanna ok? array_1[0].array_2[0].array_3[0]---> here you the information you need.

so you have 2 arrays inside array_1 at position 0.

for(){//to watch the first array all positions 
  for(){//top watch the second array idem
    for(){//to watch the 3 idem...
      here at teh position 0 take away the values... 
    }   
  }
}

it hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.