gpt4 book ai didi

php数组按多组分组

转载 作者:行者123 更新时间:2023-11-29 04:42:01 24 4
gpt4 key购买 nike

我有一组数据每组包含 3 个值,如 name 、 mobile 、 message。

如何将这些多个值存储在数组中并获得单独组的回显。??

<?php
$full_name = array( );

$full_name["name"] = "john1";
$full_name["mobile"] = "923456812536";
$full_name["message"] = "message1";

$full_name["name"] = "john2";
$full_name["mobile"] = "565656565656";
$full_name["message"] = "message2";

$full_name["name"] = "john3";
$full_name["mobile"] = "444442222222222";
$full_name["message"] = "message3";

$full_name["name"] = "john4";
$full_name["mobile"] = "2222";
$full_name["message"] = "2222222222";

echo $full_name["name"]."</br>".
$full_name["mobile"]."</br>".
$full_name["message"]."</br></br>"

?>

最佳答案

像这样插入数组:

$full_name[] = array(
"name" => "john1",
"mobile" => "923456812536",
"message" => "message1",
);

等等

给自己一个多维数组

然后循环使用

foreach($full_name as $name) {
echo $name['name'], ' ', $name['mobile'], ' ', $name['message'], PHP_EOL;
}

关于php数组按多组分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26546671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com