我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

为什么在设置之前声明数组(php)? [重复]

This question already has an answer here:

  • Is it necessary to declare PHP array before adding values with []? 11 answers

I dont know why people declare array before loops and etc..:

$new= array();      // <----- why this is needed ?
foreach($something as $v){
    $new[] = $v;
}

Why to declare the array before setting its value? (In other languages, i.e. C# and JAVA it is needed, but why in PHP?)

</div>

You're not setting its value, you're pushing a new element onto the array. But there needs to be an empty array to push onto.

近期文章

  • PHP抽象类和受保护的方法
  • 超时无法在PHP Httpful请求中工作
  • PHP:在我自己的MVC框架中包含文件?
  • 更新mysqli多列错误PHP [重复]
  • 使用PHP显示来自mysql的图像是否存在
  • php从数组中的相同键获取两个值
  • 使用Instagram api无需身份验证
  • 使用“whereNotIn”方法时出错[laravel]
  • 使用下拉列表格式化电话号码
  • 使用PHPSESSID和cookie识别用户
  • 如何使用$ _GET变量(index.php?cat = about)
  • 计算字符串中出现的数字数量
  • 访问Laravel Blade中的嵌套对象
  • Laravel 5.4注册notfoundhttpexception
  • 需要PHP和我的HTML5表单的帮助
  • PHP表单提交错误显示不成功
  • Laravel Homestead挂起了SSH Auth方法
  • 结合php循环和计数 - Wordpress ACF
  • PHP数组字符串键末尾添加数字
  • 关于标准的自定义平面文件“CMS”问题

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华