Assign array element to variable in PHP

余生长醉 提交于 2019-12-02 03:26:12

You can use:

$var = $array['message'];

In this case, message is your array index.

It's an associative array and you need to access elements by key. In your case:

$var = $array['message'];

I believe your array syntax is correct, but I like to create associative arrays this way:

$array1 = array( 'type' => 8, 'message' => "Use of undefined constant hola - assumed 'hola'", 'file' => "C:\wamp\www\WeCode\code.php(29) : eval()'d code", 'line' => 3 );

Then since this is an associative array, you can access it like this:

$var2 = $array1['message'];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!