[英]How to remove square bracket from an array?
I have an array..let say: 我有一个数组..说:
$array = [$a,$b,$c,$d];
How I can remove [
and ]
? 我如何删除
[
和]
?
The expected result would be: 预期结果将是:
$a,$b,$c,$d
I used some array function eg array_slice
but it does not fill my requirement. 我使用了一些数组函数,例如
array_slice
但它不能满足我的要求。 Any ideas? 有任何想法吗?
Note: I need to pass all array elements to function as argument. 注意:我需要传递所有数组元素以用作参数。
e.g: function example($a,$b,$c)
it sounds like you're after a string representation of the array, try using join()
or implode()
like this: 听起来像是在数组的字符串表示形式之后,请尝试使用
join()
或implode()
如下所示:
<?php
$array = [$a,$b,$c,$d];
$str = join(",", $array); // OR $str = implode(",", $array);
echo $str;
EDIT 编辑
after reading your question a little more carefully, you're trying to pass the array into a function call, to do that you need to use call_user_func_array()
: 在更仔细地阅读了您的问题之后,您尝试将数组传递给函数调用,以执行此操作,您需要使用
call_user_func_array()
:
<?php
function function_name($p1, $p2, $p3, $p4){
//do something here
}
$array = [$a,$b,$c,$d];
call_user_func_array('function_name', $array);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.