1

I got this array output in php:

Array
(
    [blabla0] => Array
        (
            [0] => lalala
            [1] => lelele
        )

    [blabla1] => Array
        (
            [0] => lalala
            [1] => lelele
        )

)

If I'd like to print by associative name, it's like this: $myArray['blabla0'][0] , and it works. But I want to do like this: echo $myArray[0][0], by index...is there any way?

3
  • 2
    maybe with a foreach loop Commented Dec 11, 2014 at 17:02
  • 1
    echo $myArray[array_keys($myArray)[0]][0];.... requires PHP >= 5.4 for the array dereferencing Commented Dec 11, 2014 at 17:03
  • @MarkBaker that same thing can be lengthened a bit to support older versions, as such: $arr_keys=array_keys($myArray); echo $myArray[$arr_keys[0]][0], and OP you can do that with for/foreach loops as well Commented Dec 11, 2014 at 17:09

1 Answer 1

1

Mark bakers answer is best for one option. You can convert all of the array with array_values eg

$new_array = array_values($old_array);
echo $new_array[0][0];

It depends how many times you wish to access the array

http://php.net/manual/en/function.array-values.php

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

1 Comment

Thanks everyone, you help me so much! I could do it converting, and I think it'll work for me this way.

Your Answer

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