保存数组与逗号在三元条件php


save array with commas in ternary condition php

我有一个数组

$this->input->post("first_array")={ one two three }

我需要创建一个数组它将包含几个这样的数组

所以我正在做一个' first_array '来保存数组,首先验证它确实是一个数组,然后如果它没有设置,我放一个'未定义'字符串

array(
'fisrt_array' => is_array($this->input->post("first_array")) ? implode(' ',$this->input->post("first_array"))   : 'Not defined'
);

如果它被设置了,我内爆保存在$this->input->post("first_array")中的数组

都是正确的,但是我将结果存储为one two three而不是one,two,three

如何保存该格式的数组?

如果我做implode(',',$this->input->post("first_array"),我会存储 1,2,3,,最后不需要逗号…

implode(',',$this->input->post("first_array")不能在最后一个元素后加逗号。

这应该对你有用。话虽如此,你在用一种奇怪的方式声明你的数组。

使用$this->input->post['First_Array'] = array('One', 'Two', 'Three');

如果你只是想将你的数组添加到另一个数组(在PHP中,我们将数组的数组称为"多维数组"),只需执行:

second_array[] = $this->input->post['First_Array'];