Php 如何绑定数组?

Php 如何绑定数组?,php,arrays,Php,Arrays,假设我有这3个阵列: Product(milk,candy,chocolate) Colors(white,red,black) Rating(8,7,9) 如何创建一个循环来绑定这些数组,以便在每个循环中获得3个变量:$product$color$rating 通过示例,我将输出如下: 牛奶为白色,评级为8/10 糖果为红色,评级为7/10 巧克力为黑色,评级为9/10 谢谢例如,通过使用SPL 例如,通过使用SPL 我不知道我是否做对了。 但是你想要这样的东西吗 $products = a

假设我有这3个阵列:

Product(milk,candy,chocolate)
Colors(white,red,black)
Rating(8,7,9)
如何创建一个循环来绑定这些数组,以便在每个循环中获得3个变量:
$product
$color
$rating

通过示例,我将输出如下:

牛奶白色,评级为8/10

糖果红色,评级为7/10

巧克力黑色,评级为9/10

谢谢

例如,通过使用SPL

例如,通过使用SPL


我不知道我是否做对了。 但是你想要这样的东西吗

$products = array("milk", "candy", "chocolate");
$colors = array("white", "red", "black");
$ratings = array(8, 7, 9);

 for($i = 0; $i < sizeof($products); $i++) {
    $product = $products[$i];
    $color = $colors[$i];
    $rating = $ratings[$i];

    echo $product . ' is ' . $color . ' and has a rating of ' . $rating . '/10 <br/>';
 }

我不知道我是否做对了。 但是你想要这样的东西吗

$products = array("milk", "candy", "chocolate");
$colors = array("white", "red", "black");
$ratings = array(8, 7, 9);

 for($i = 0; $i < sizeof($products); $i++) {
    $product = $products[$i];
    $color = $colors[$i];
    $rating = $ratings[$i];

    echo $product . ' is ' . $color . ' and has a rating of ' . $rating . '/10 <br/>';
 }

首先,你无法像
数组(数组('milk','white',8),数组('candy','red',7),…)
那样构造/检索它。你也无法像
数组(数组('milk','white',8),数组('candy',red',7),…)
那样构造/检索它。哇,从没听说过乘法器,我需要更多地学习SPL库,谢谢!哇,从没听说过乘法器,我需要更多地研究SPL库,谢谢!
$products = array("milk", "candy", "chocolate");
$colors = array("white", "red", "black");
$ratings = array(8, 7, 9);

 for($i = 0; $i < sizeof($products); $i++) {
    $product = $products[$i];
    $color = $colors[$i];
    $rating = $ratings[$i];

    echo $product . ' is ' . $color . ' and has a rating of ' . $rating . '/10 <br/>';
 }
milk is white and has the rating of 8/10
candy is red and has the rating of 7/10
chocolate is black and has the rating of 9/10