php - PHP 中的数组串联

标签 php arrays

我们如何连接两个关联数组? 例如: 数组1

$numbers = array();
$numbers['id'] = 4;
$numbers['num'] = 391; 
$numbers['rupees'] = 'Adeel';

数组2

$numbers1 = array();
$numbers1['id'] = 5;
$numbers1['num'] = 392; 
$numbers1['name'] = 'shah';

结果应该是这样的

id   num  name
4    391  Adeel
5    392  waqar

我该怎么办???

最佳答案

根据您的示例,您不需要连接它们。您需要将它们放在同一个数组中:

$numbers = array();
$numbers['id'] = 4;
$numbers['num'] = 391; 
$numbers['rupees'] = 'Adeel';

$numbers1 = array();
$numbers1['id'] = 5;
$numbers1['num'] = 392; 
$numbers1['name'] = 'shah';

$all[] = $numbers;
$all[] = $numbers1;

这样,您将获得与从数据库获取的内容一致的内容。

关于php - PHP 中的数组串联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4416804/

相关文章:

php - PIN 码认证

php - 结合来自两个不同表的 SQL 值并对其使用算术

c - 用 C 语言中另一个字符串中的字符替换字符串字符

arrays - Swift 性能中的 xy 数组

Java如何像Python一样将两个或多个数组附加到新数组中

php - 如何将生成的 MySQL 行存储到数组中?

php - 如何从多个表中获取数据并在laravel中使用 '->with()'发送到html

php - 列出 channel 中已安装的包

arrays - 用未知形状填充网格

javascript - 为什么不工作? Onclick JavaScript