简体   繁体   中英

I want only values of 1st index then 2nd and then 3rd index. How can I iterate through this with a loop and get the values dynamically?

I want the values from this array for each index. I tried to access the values using foreach but I can´t figure out how to get all values for each index (ie for 1st, 2nd, 3rd)

Array
    (
        [1] => Array
            (
                [0] => 244
                [1] => 6014
                [2] => 5067
                [3] => 5059
                [4] => 1726
                [5] => 56
                [6] => 1234
                [7] => 56
            )

        [2] => Array
            (
                [0] => 122
                [1] => 123
                [2] => 56
                [3] => 246
                [4] => 7360
                [5] => 8058
                [6] => 1290
                [7] => 1234
                [8] => 5454
            )

        [3] => Array
            (
                [0] => 7890
                [1] => 5454
            )

    )

Follow this sample I made, if you still don't get it, leave a comment.

$array = array(
        array('abc','def','xyz'),
        array('asd','fun','bad'),
        array('blue','red','green')


 );

foreach($array as $key=>$value){
    foreach($value as $subkey=>$subvalue) {
        echo $subkey . " : " . $subvalue . "<br>";
    }
}

If you want to get the currency pair key also, use this example:

$assoc_array = array(
        "eurusd" =>     array('abc','def','xyz'),
        "usdjpy" =>     array('good','bad','ugly'),
        "aususd" =>     array('blue','red','green')

);

foreach($assoc_array as $key=>$value){
        echo $key . ":: <br>";
    foreach($value as $subkey=>$subvalue) {
        echo $subkey . " : " . $subvalue . "<br>";
    }
}

I want to show result this way

Please try this. hopefully It will help u.

foreach ($array as $currencyId => $subArray){ 
    echo $currencyId . "<br>";

            foreach ($subArray as $value) {

                echo $value . "<br>";
            }
        }

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