【发布时间】:2014-02-25 16:32:22
【问题描述】:
我有以下 PHP 多维数组,我希望尝试选择 4 个随机项目,然后用标题、图像和文本显示它们。使用我使用的代码,我似乎得到了一个随机的数字,而不是我需要的。
<?php
$arr = array(
array(
"image" => "",
"title" => "Open 7 days.",
"text" => "We’re open 7 days a week."
),
array(
"image" => "",
"title" => "Well done",
"text" => "Well done you done great."
),
array(
"image" => "",
"title" => "Rice",
"text" => "Various flavours"
),
array(
"image" => "",
"title" => "Rooms",
"text" => "Roomy rooms for a roomyful time"
),
array(
"image" => "",
"title" => "Keep in touch.",
"text" => "Stay in touchwith us as we'll miss you"
),
array(
"image" => "",
"title" => "Location",
"text" => "We'll show you where we are."
),
array(
"image" => "",
"title" => "The Home",
"text" => "See our home page"
)
);
print_r(array_rand($arr));
【问题讨论】:
标签: php arrays function multidimensional-array