Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

php二维数组如何快速查找对应字段值?

Array
(
    [0] => Array
        (
            [id] => 1
            [field_name] => 姓名
            [field_type] => 1
            [field_tips] => 请输入姓名
            [hidden] => 1
            [multi_line] => 1
            [require] => 
            [sort] => 
        )

    [1] => Array
        (
            [id] => 2
            [field_name] => 性别
            [field_type] => 2
            [field_tips] => 请选择性别
            [hidden] => 1
            [multi_line] => 0
            [require] => 
            [sort] => 
        )

    [2] => Array
        (
            [id] => 3
            [field_name] => 电话
            [field_type] => 1
            [field_tips] => 请输入电话
            [hidden] => 1
            [multi_line] => 0
            [require] => 
            [sort] => 
        )
)

怎样根据id值取出,此id对应的 multi_line,字段的值。

例如:id=3,取出的multi_line = 0

我记得php好像有这种内置的数组函数,找半天没找到。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

不知道你是不是想的这个:

$map = array_column($list, 'multi_line', 'id');
echo $map[1]; // 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...