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

如何将字符串设置为数组并设置数组最大值

I want to make an array with the same value and set the array to be maximum based on my counter.

For example, I want to create an array with a string "hello" and I want it to keep going until the number of array is 3.

How is that possible using php with yii2 framework?

you can use a for loop this way

$array= array();
for($i=0;$i<3;$i++){
   $array[] = "hello";
}

You will get $array with 3 hello.

try array_fill

$count = 5;
$a = array_fill(0, $count, 'hello');

近期文章

  • 通过mysqli搜索忽略非字母数字字符
  • php mysql查询输出文件
  • 使用php运行Javascript代码
  • 对数组进行排序并获取密钥
  • php pdo sql如果存在行则返回
  • PHP数组到jquery选择框
  • 为什么这个date_diff不起作用?
  • 坚持等级检查消息的“if”[关闭]
  • 如何在mysql中连接字段表格
  • 如何在数据库中存储员工体验数据
  • 使用godaddy如何使用标题(“位置:URL”)
  • 使用左连接查询创建列
  • 在浏览页面时突出显示列表元素
  • 如何解决遇到codeigniter3的PHP错误
  • PHP和PHPMyAdmin之间的查询执行时间的差异
  • 选择一行中的列并使用python和mysqldb保存为变量
  • 获取dom文件内容作为多维数组
  • 使用Php在Stripe中使用Checkout
  • Redis群集的配置
  • 来自Firebird数据库的ibase_fetch_object后未显示数据

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华