0

I have an array list like

[1] => Array
   (
       [name] => Linda
       [age] => 23
       [country] => USA
   )

[2] => Array
   (
       [name] => Fleur
       [age] => 16
       [country] => France
   )

How do I remove the keys [1], [2] from the array so I get an output like

Array
   (
       [name] => Linda
       [age] => 23
       [country] => USA
   )

Array
   (
       [name] => Fleur
       [age] => 16
       [country] => France
   )
2
  • You can do that.You should learn the basic. Commented Feb 27, 2014 at 15:53
  • What is the point of separately printing each row with print_r()? What are you actually trying to achieve? Commented Sep 23, 2024 at 5:22

3 Answers 3

2

If you want just to print the output you want, you can just do this:

print_r($arr[1]);
print_r($arr[2]);

There's really not a "removal" option since the "1" and "2" keys you have there are exist for sorting your other subarrays which have similar keys (like name). It's a kind of overwriting..

Even the simplest array like:

$arr = array(5,8);

is in fact:

Array
(
   [0] => 5
   [1] => 8
)
Sign up to request clarification or add additional context in comments.

Comments

1

loop though and do each one individually

foreach($array as $val) {
    print_r($val);
}

Comments

0

Any element of an array is a key-value pair. So you can't have an item without key.

If it's just a matter of output, please do not use var_dump() as a way to output things to your end-user.

You can simply iterate through your main array with a foreach loop, and display items in a user-friendly way.

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.