简体   繁体   English

发送数组到PHP中的功能

[英]send array to function in php

Here is the code : 这是代码:

function dosomething ()
{
  ... do something with the array... like print value !
}

$ar = array(1,2,3);
dosomething ($ar);

That piece of code work fine... 那条代码工作得很好......

What i try to do is to pass the array DIRECTLY to the function i have try this, non work... HELP ! 我尝试做的是直接将数组传递给我尝试过的功能,非工作......帮助!

dosomething ([12,32,56]);
dosomething ({12,45,87});
dosomething ("[98,74,52]");
dosomething( array(12,32,56) );

first you have to specify the parameter in the function: 首先,您必须在函数中指定参数:

function dosomething($array) { var_dump($array); }

Then you have to pass the array and define it like you did in your code but directly in the function: 然后你必须传递数组并像在代码中那样定义它,但是直接在函数中:

dosomething(array(1,2,3));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM