按设定值自动递增的数组值(例如,如果第一个是 echo $myarray[5];下一个将是 echo $myarray[5+5];所以真的是 $myarray[10];)
array values that auto increment by a set value (eg if 1st is echo $myarray[5]; the next would be echo $myarray[5+5]; so really $myarray[10];)
得到一个这样的数组..
Array
(
[1] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
)
[2] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
[5] => Order Number
[6] => Item 2 Colour
[7] => Buyer Name
[8] => Item 2 Name
[9] => Item 2 Variation
)
[3] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
[5] => Order Number
[6] => Item 2 Colour
[7] => Buyer Name
[8] => Item 2 Name
[9] => Item 2 Variation
[10] => Order Number
[11] => Item 3 Colour
[12] => Buyer Name
[13] => Item 3 Name
[14] => Item 3 Variation
)
}
这显示了 3 个虚拟订单,在此示例中,第一个订单有 1 个商品,second-order 有 2 个商品,第三个订单有 3 个商品。如您所见,添加的项目越多,该项目的数组就会变得更长,并且数字总是在一定数量的块中增加。即上面示例中第 2 项中第一项的标题是 [3],然后第 2 项的标题是 [8](与之前相同加 5)
然后在示例 3 中,它的 [3]、[8] 和 [13] 所以基本上总是从前面的数字 ref
中加上 5
那么有没有办法回显一个值加上 prev 值的 5 并一直这样做呢
喜欢
$item1title = $myarray[5];
$item2title = $item1title[+5];
$item3title = $item2title[+5];
echo $item1title;
echo $item2title;
echo $item2title;
这是一个简单的示例,说明如何以更有用的方式构建数组。如评论中所述,我们创建了一个主订单数组。在该数组中,每个订单都有一个条目。这些订单中的每一个也是一个数组,包含订单的详细信息以及项目。这些项目包含在一个数组中,每个项目都是数组中的一个条目。每个项目本身也是一个数组,条目是项目详细信息。
$orders = array(
array(
"orderNum" => 123,
"buyerId" => 111,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
)
)
),
array(
"orderNum" => 456,
"buyerId" => 444,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
),
array(
"id" => 356,
"name" => "Item Two",
"color" => "green"
)
)
),
array(
"orderNum" => 789,
"buyerId" => 765,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
),
array(
"id" => 356,
"name" => "Item Two",
"color" => "green"
),
array(
"id" => 999,
"name" => "Item Three",
"color" => "blue"
)
)
)
);
这里是一个快速示例,说明您可以如何访问订单和商品
foreach($orders as $order)
{
echo "Order number: " . $order["orderNum"] . "\r\n";
foreach($order["items"] as $item)
{
echo "Item Name: " . $item["name"] . "\r\n";
}
echo "\r\n";
}
得到一个这样的数组..
Array
(
[1] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
)
[2] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
[5] => Order Number
[6] => Item 2 Colour
[7] => Buyer Name
[8] => Item 2 Name
[9] => Item 2 Variation
)
[3] => Array
(
[0] => Order Number
[1] => Item 1 Colour
[2] => Buyer Name
[3] => Item 1 Name
[4] => Item 1 Variation
[5] => Order Number
[6] => Item 2 Colour
[7] => Buyer Name
[8] => Item 2 Name
[9] => Item 2 Variation
[10] => Order Number
[11] => Item 3 Colour
[12] => Buyer Name
[13] => Item 3 Name
[14] => Item 3 Variation
)
}
这显示了 3 个虚拟订单,在此示例中,第一个订单有 1 个商品,second-order 有 2 个商品,第三个订单有 3 个商品。如您所见,添加的项目越多,该项目的数组就会变得更长,并且数字总是在一定数量的块中增加。即上面示例中第 2 项中第一项的标题是 [3],然后第 2 项的标题是 [8](与之前相同加 5) 然后在示例 3 中,它的 [3]、[8] 和 [13] 所以基本上总是从前面的数字 ref
中加上 5那么有没有办法回显一个值加上 prev 值的 5 并一直这样做呢
喜欢
$item1title = $myarray[5];
$item2title = $item1title[+5];
$item3title = $item2title[+5];
echo $item1title;
echo $item2title;
echo $item2title;
这是一个简单的示例,说明如何以更有用的方式构建数组。如评论中所述,我们创建了一个主订单数组。在该数组中,每个订单都有一个条目。这些订单中的每一个也是一个数组,包含订单的详细信息以及项目。这些项目包含在一个数组中,每个项目都是数组中的一个条目。每个项目本身也是一个数组,条目是项目详细信息。
$orders = array(
array(
"orderNum" => 123,
"buyerId" => 111,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
)
)
),
array(
"orderNum" => 456,
"buyerId" => 444,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
),
array(
"id" => 356,
"name" => "Item Two",
"color" => "green"
)
)
),
array(
"orderNum" => 789,
"buyerId" => 765,
"items" => array(
array(
"id" => 321,
"name" => "Item One",
"color" => "red"
),
array(
"id" => 356,
"name" => "Item Two",
"color" => "green"
),
array(
"id" => 999,
"name" => "Item Three",
"color" => "blue"
)
)
)
);
这里是一个快速示例,说明您可以如何访问订单和商品
foreach($orders as $order)
{
echo "Order number: " . $order["orderNum"] . "\r\n";
foreach($order["items"] as $item)
{
echo "Item Name: " . $item["name"] . "\r\n";
}
echo "\r\n";
}