0

The array structure is like this

    $array1 = [
   "101" => [
        "name" => "Robin",
        "age" => "25"
    ],
    "102" => [
        "name" => "asRobin",
        "age" => "25"
    ],
    "103" => [
        "name" => "Roasbin",
        "age" => "25"
    ],
    "104" => [
        "name" => "Robiasn",
        "age" => "25"
    ]
  ]

Here I got the ids in a particular array using $ids = array_keys($array1) function. Now likewise how can i extract the names

1
  • What do you want to do with them when you have them? Commented Aug 1, 2017 at 15:33

2 Answers 2

4

With array_map :

$names = array_map(function($a) { return $a["name"]; }, $array1);
Sign up to request clarification or add additional context in comments.

Comments

3

EDIT : I just remembered that function, which gives a more elegant way to do that :

$names = array_column($array1);

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.