Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建一个与pg_fetch_all()结构相同的数组_Php_Arrays - Fatal编程技术网

Php 创建一个与pg_fetch_all()结构相同的数组

Php 创建一个与pg_fetch_all()结构相同的数组,php,arrays,Php,Arrays,我需要重新创建一个与pg\u fetch\u all()函数具有相同结构的数组,但我无法理解其概念: 我试图通过循环查询字符串创建它,当查询字符串的键匹配时,添加值: 这是我尝试的方式,但它只存储for循环的最后一个值: foreach($_REQUEST as $key => $x) { if(strpos($key,"tldid_loc_") !== false) { $currlocation = $x; } if(strpos($key,

我需要重新创建一个与
pg\u fetch\u all()
函数具有相同结构的数组,但我无法理解其概念:

我试图通过循环查询字符串创建它,当查询字符串的键匹配时,添加值:

这是我尝试的方式,但它只存储for循环的最后一个值:

foreach($_REQUEST as $key => $x) {
    if(strpos($key,"tldid_loc_") !== false) {
        $currlocation = $x; 
    }

    if(strpos($key,"tldid_action_") !== false) {
        $arr_new_trip["tldlocation"] = $currlocation;
        $arr_new_trip["tldaction"] = $x;
    }
}
我需要的是复制DB表的结构,如:

tldlocation|tldaction
a          | b
c          | d
e          | f
使用
var\u dump($\u请求)
查询字符串输出:

当我在这个数组中循环时,如果我找到
tldid\u loc\u XXX
我存储该值,那么下一个值(tldid\u action\u XXX)就是我的值

我要查找的数组的结构是(查看第一个值):


等等。

请显示
$\u REQUEST
的内容和所需的输出(以数组形式)。也许您想要的是?如何使用
parse_str()
添加一个键我的键不是来自查询字符串,而是值,很难从您的原始帖子中分辨出来。不,你不能用它定义键。
array(17) { ["tripid"]=> string(2) "50" ["tldid_loc_1"]=> string(1) "1" ["tldid_action_494"]=> string(12) "LOADING DATE" ["tldid_action_495"]=> string(14) "DEPARTURE DATE" ["tldid_loc_3"]=> string(1) "3" ["tldid_action_496"]=> string(12) "ARRIVAL DATE" ["tldid_action_497"]=> string(14) "DEPARTURE DATE" ["tldid_loc_6"]=> string(1) "6" ["tldid_action_499"]=> string(15) "OFFLOADING DATE" ["tldid_action_500"]=> string(14) "DEPARTURE DATE" ["tldid_action_498"]=> string(12) "ARRIVAL DATE" ["tldid_loc_8"]=> string(1) "8" ["tldid_action_501"]=> string(12) "ARRIVAL DATE" ["tldid_action_502"]=> string(14) "DEPARTURE DATE" ["tldid_loc_7"]=> string(1) "7" ["tldid_action_503"]=> string(12) "ARRIVAL DATE" ["tldid_action_504"]=> string(15) "OFFLOADING DATE" }
tldlocation|tldaction
1          |LOADING DATE
1          |DEPARTURE DATE
3          |LOADING DATE
3          |DEPARTURE DATE