在php中创建和使用多维数组
$breakfast = array(
'rest_id' => $rest_id ,
'type' => 'Breakfast' ,
'value' => $bprice
);
$lunch = array(
'rest_id' => $rest_id ,
'type' => 'Facilities' ,
'value' => $lprice
);
$dinner = array(
'rest_id' => $rest_id ,
'type' => 'Facilities' ,
'value' => $dprice
);
$data = $breakfast . $lunch . $dinner;
我创建数组 $data 的方式正确吗?如果是的话...现在如果我想将数组早餐传递给一个函数,我该如何获取其中的数组早餐?
我想做这样的事情:
$this->db->insert_breakfast($breakfast);
那么我现在如何从 $data 中获取早餐数组呢?
$breakfast = array(
'rest_id' => $rest_id ,
'type' => 'Breakfast' ,
'value' => $bprice
);
$lunch = array(
'rest_id' => $rest_id ,
'type' => 'Facilities' ,
'value' => $lprice
);
$dinner = array(
'rest_id' => $rest_id ,
'type' => 'Facilities' ,
'value' => $dprice
);
$data = $breakfast . $lunch . $dinner;
Is the way i created the array $data correct? If yes... now how do i get the array breakfast inside it, if i want to pass it to one function?
I want to do something like this:
$this->db->insert_breakfast($breakfast);
So how do i get breakfast array out of $data now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望
$breakfast
、$lunch
和$dinner
在$data
中创建多维数组,您需要将您的作业替换为以下内容。然后您可以访问其中任何一个,例如
$data['breakfast']['value']
。我不太明白DB部分。回复评论,我很乐意提供帮助。
If you want
$breakfast
,$lunch
and$dinner
to make a multi-dimensional array in$data
, you will need to replace your assignment with the following.Then you can access any of them like
$data['breakfast']['value']
.I didn't quite understand the DB part. Comment back and I'd be glad to help.
正确的是
.
运算符表示字符串连接。您可以使用$data[0]
访问$breakfast
,因为它是第一个成员。您还可以使用关联数组;请参阅@Jason 的回答。The correct is
The
.
operator means string concatenation. You can access$breakfast
with$data[0]
, since it's the first member. You can also use associative arrays; see @Jason's answer.