开发者

get particular column value

开发者 https://www.devze.com 2022-12-24 14:52 出处:网络
i want take the particular column all valu开发者_如何学Ce in multidimensional array... i need to get the value of or column (\"rose\",\"daisy\",\"orchid\")...

i want take the particular column all valu开发者_如何学Ce in multidimensional array...

i need to get the value of or column ("rose","daisy","orchid")...

how do get?

is there any predefined function? because in my array have 1000 record, so loop will continue to run 1000 times, program will slow, so...


Iterate through each array in the array, choosing only one key (Sorry if that sounds a bit confusing, here's what I mean):

$flowers = array();
$flowers[] = array('type'=>'rose', 'color'=>'red');
$flowers[] = array('type'=>'daisy', 'color'=>'white');
$flowers[] = array('type'=>'orchid', 'color'=>'pink');

foreach ($flowers as $flower) {
    echo $flower['type'];
}

This will print out whatever's in column 'type' for each flower.


<?php
$shop = array( array("rose", 1.25 , 15),
               array("daisy", 0.75 , 25),
               array("orchid", 1.15 , 7)
          );

echo $shop[0][0]." costs ".$shop[0][1]." and you get ".$shop[0][2]."\n";
echo $shop[1][0]." costs ".$shop[1][1]." and you get ".$shop[1][2]."\n";
echo $shop[2][0]." costs ".$shop[2][1]." and you get ".$shop[2][2]."\n";

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消