English 中文(简体)
根据储存在钥匙内的数值,从两维阵列中得出的标值?
原标题:Pick value from two-dimensional array based on value stored inside key?

Hi friends i am working on survey i need to extract an array from an array stored inside it

如何做到这一点,就要寻找基于问题的解决办法,例如13。

i 与我有问题。 回答阵列与问题有关。

如何从主要阵列中抽取问阵列和回答阵列,其依据是问题的价值,例如13

now if i need the array which has the question id along with its associated id how to do it then from my array structure?

我的法典就是这样。

Array
(
    [0] => Array
        (
            [que_info] => Array
                (
                    [question_id] => 13

                    [description] => Overall Customer Satisfaction.




                )

            [answers] => Array
                (
                    [0] => Array
                        (
                            [answer_id] => 45

                            [answer_text] => Very dissatisfied

                        )


                )

        )

    [1] => Array
        (
            [que_info] => Array
                (
                    [question_id] => 14

                    [description] => Progress (often referred to as Task Resolution or similar)


                )

            [answers] => Array
                (
                    [0] => Array
                        (
                            [answer_id] => 52

                            [answer_text] => None

                        )

                    [1] => Array
                        (
                            [answer_id] => 53

                            [answer_text] => Very little

                        )


                        )



                )

        )

任何帮助都将得到赞赏:

最佳回答

首先,这不是一个2D阵列,这个阵列 s树。 2D阵列始终包含每个阵列的元素阵列[x][y],从未有过任何阵列。

随便穿透阵列,如果你发现一个与问题贴近的元素,则填写一份答复清单。

例:

  foreach($questions as $question) {
    if($question[ que_info ][ question_id ] === $questionId)
      return $question[ answers ];
  }
问题回答
function find_question($array, $id) {
    foreach ($array as $arr)
    {
        if ($arr[ que_info ][ question_id ] == $id)
            return $arr;
    }
}

var_dump(find_question($array, 13));
var_dump(find_question($array, 14));




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签