-2
陣列內容我有一個數組:PHP - 在可變
$people = "array(
"t1:sdfdsf774",
"t2:dsfdsf",
);
我有保持所述陣列的內容的變量稱爲$內容。
我想獲得$內容到數組如下:
$people = "array(".$content.")";
我不斷收到一個語法錯誤。
陣列內容我有一個數組:PHP - 在可變
$people = "array(
"t1:sdfdsf774",
"t2:dsfdsf",
);
我有保持所述陣列的內容的變量稱爲$內容。
我想獲得$內容到數組如下:
$people = "array(".$content.")";
我不斷收到一個語法錯誤。
首先你爲什麼要用「」來定義一個數組?
$people = "array(".$content.")";
在這種類型的減速,究竟正在發生的是字符串「陣列(」被串聯到數組$含量不能發生。
該陣列可以爲初始化(觀察沒有引號)
$people = array("t1:sdfdsf774", "t2:dsfdsf");
這將創建一個數組如下:
Array
(
[0] => t1:sdfdsf774
[1] => t2:dsfdsf
)
如果這是ü如何努力創造現在,如果你想$內容添加到$的人,然後使用array_merge如下:
$people = array_merge($people, $content)
如果你想t1和t2爲鍵,那麼你應該如下初始化數組:
$people = array(t1=>"sdfdsf774", t2=>"dsfdsf");
下面這樣的創建:
Array
(
[t1] => sdfdsf774
[t2] => dsfdsf
)
然後array_merge與$ content。要將數組追加到$ people,請使用array_push($people, $content)
。不需要減速。
'array($ content)';也許 – devpro
你正在創建一個字符串..不是一個數組。當你定義一個數組時,你可以這樣做:'$ people = array(「something」,「something else」);'閱讀文檔:http://us2.php.net/manual/en/function.array .php(在問這裏之前應該是你的第一站)。 –
真的不清楚......你想通過這樣做來達到什麼目的? –