如何在php数组中为一个键存储多个值 [英] how to store multiple values for one key in php array

查看:175
本文介绍了如何在php数组中为一个键存储多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了很多搜索,找到了一种将多个值存储到一个键中的方法,但是我什么都没有

i searched a lot to find a way to store multiple value into one key , but i can't anything

我需要为一个键设置3个值php array

I need to set 3 value for one key in php array

是否可以做到这一点?

推荐答案

到直接回答您的问题,不。 PHP数组只能包含一组密钥数据。

To directly answer your question, no. PHP arrays can only contain one set of data for the key.

您需要使用多维数组,其中键的值是包含键和值的数组,例如:

You need to use a multidimensional array, where the value of a key is an array with keys and values, e.g.:

$array = array
  (
    "bob" => array
                    (
                      "height" => "6.0",
                      "age" => "21",
                    ),
    "joe" => array
                    (
                      "height" => "5.9",
                      "age" => "35",
                    )
  );

这里是基础知识的起点

在那之后,堆栈上已经有大量信息溢出和互联网的其余部分。搜索 php多维数组

After that, there's a mountain of info already on Stack Overflow and the rest of the internet. Search for "php multidimensional array"

搜索在堆栈上

这篇关于如何在php数组中为一个键存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆