且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php:推送到可能存在或可能不存在的数组

更新时间:2023-11-26 18:16:52

检查数组是否首先存在,如果不存在,则创建它...然后添加元素,知道该数组肯定会在之前定义手:

Check if the array exists first, and if it doesn't, create it...then add the element, knowing that the array will surely be defined before hand :

if (!isset($myArray)) {
    $myArray = array();
}

array_push($myArray, 'my message');