简体   繁体   中英

add data to multidimensional php array

I have an array that outputs the following:

Array
(
    [0] => Array
        (
            [0] => wordpress
        )

    [1] => Array
        (
            [0] => wordpress
            [1] => forms
        )

    [2] => Array
        (
            [0] => wordpress
            [1] => galleries
        )

    [3] => Array
        (
            [0] => wordpress
            [1] => ecommerce
        )

    [4] => Array
        (
            [0] => wordpress
            [1] => ecommerce
            [2] => wp-e-commerce
        )
)

How would i go about adding an item into the [0] => Array ?

This is the way i have created my array:

$cats = array();
foreach($items as $x=> $item) {

        $ex = explode("/",$item['path']);
        $cats[] = explode("/",$item['path']);

        echo $item['name'].' - '. $item['path'];
        echo "<br>";
    }

print_r($cats);

Any help would be greatly appreciated!

Thanks

If I understand the question correctly, something like:

array_push($cats[0],'something else');

should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM