0

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..

5
  • $arr["bla123"][0]; // 2 Commented Jun 16, 2015 at 7:52
  • try to print $array['bla123'][0] Commented Jun 16, 2015 at 7:52
  • array_count_values Commented Jun 16, 2015 at 7:53
  • its completely dynamic i wont be knowing what the values will be Commented Jun 16, 2015 at 7:54
  • Did you tried anything by yourself Commented Jun 16, 2015 at 8:33

1 Answer 1

1

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
        }
    }

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

1 Comment

dude can you please look at this one. am really struggling with objects in php Here is the Link

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.