0

So basically I have array -

Array (
    [0] => Array 
    (
        [name] => my_name
        [year] => my_year
        [other] => Array
        (
            [0] => Yes
            [1] => No
            [2] => Other_values
        }
    )

    [1] => Array 
    (
        [name] => my_name2
        [year] => my_year2
        [other] => Array
        (
            [0] => Yes2
            [1] => No2
            [2] => Other_values2
        }   
    )
)

So basically I would remove the indexes from the last subArray which are both [other] arrays.

Well basically how I would like it to be displayed is -

Array (
    [0] => Array 
    (
        [name] => my_name
        [year] => my_year
        [other] => Array (Yes, No, Other_values )
    )

    [1] => Array 
    (
        [name] => my_name2
        [year] => my_year2
        [other] => Array (Yes2, No2, Other_values2 )
    )
)

Basically without indexes.

Is it even possible, and if it isn't, then maybe it's possible at the creation of the array?

I'm creating it with the array_push(); function.

If you need my PHP code of the array_push(); function, just give me a notice.

Hope you understood what I ment, if something is unclear, you are welcome to ask me, I'll try to explain more :)!

3 Answers 3

2

Basically it is just var_dump behaviour to show keys in output. Every array has to have key - even if you do not specify it, keys exist to provide access to the elements.

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

3 Comments

So basically as far as I understood if I will remove the indexes, they will still be there, just hidden, yes?
No, PHP arrays are by nature associative arrays (key => value). Even if you do not set keys for lists of values, there will always implicitly be integer index keys. You can't actually remove them. If you're doing any sort of processing with the array where you want to use them as a list, they will behave as a list; you can simply ignore the key index.
It seems, I had problem in my php code. Don't know why but I was pushing the other array values inside another array, that caused the problem. Removed the last array, and now it's working. Thanks, you pointed me to the correct path :)!
1

You are doing that in right way, that is only representation of array when you use var_dump. or print_r to see array elements. There will be no issue if you loop through inner array using numeric index.

Comments

1

An array always will have indexes, because their are used to manipulate the array so I don't know way to remove the index but keep the value (except text representation of the array).

If you want dump information to be in one line u can use serialize or json_encode

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.