Bivin
Bivin

Reputation: 106

Getting data from an object array

I have an array

Array (
    [bla123] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 2
            [3] => 2
            [4] => 2
            [5] => 2
            [6] => 2
            [7] => 2
            [8] => 2
        )

    [12xye] => Array
        (
            [0] => 4
            [1] => 3
            [2] => 3
            [3] => 2
            [4] => 2
            [5] => 4
            [6] => 2
            [7] => 2
            [8] => 2
        )

)

How can i access this array in php and also get the number of 1,2,3.. etc from it in php. The logic is to get the rating of a products. the data is fetched from the database completely and then sorted using php. for eg: product1 one star:1 two star:3 three star:2 etc... somewhat like a star system in flipkart, amazons etc..

Upvotes: 0

Views: 75

Answers (1)

Sourabh Kumar Sharma
Sourabh Kumar Sharma

Reputation: 2807

use the below code:

<?php

    $mainArrDat = array('bla123'=>array('Your_Array_Data_Here'),'12xye'=>('Your_Array_Data_Here'));

    foreach( $mainArrDat as $mainArr )
    {
        foreach($mainArr as $nowArr)
        {
         //you can access the data that you require from $nowArr
        }
    }

    ?>

Upvotes: 1

Related Questions