Firoz P.J
Firoz P.J

Reputation: 27

How to split given array and get value from array using php

Split below array and get values like

Category
Brand
Subcategory
Packaging
Packing

Array
 (
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [col_ref_name] => Category
                )

        )

    [1] => Array
        (
            [0] => stdClass Object
                (
                    [col_ref_name] => Brand
                )

        )

    [2] => Array
        (
            [0] => stdClass Object
                (
                    [col_ref_name] => Subcategory
                )

        )

    [3] => Array
        (
            [0] => stdClass Object
                (
                    [col_ref_name] => Packaging
                )

        )

    [4] => Array
        (
            [0] => stdClass Object
                (
                    [col_ref_name] => Packing
                )

        )
)

Upvotes: 0

Views: 67

Answers (1)

Altaf Hussain
Altaf Hussain

Reputation: 5202

use a code like below :

foreach($yourArray as $array) 
{

     echo $array[0]-> col_ref_name . "<br>";
}

Your array has objects in the sub array and col_ref_name is the property of that objects, so i used a foreach loop to go through all elements of the array (which are objects) and then access the data in the col_ref_name.

I hope this will help.

Upvotes: 1

Related Questions