2

I have a array $param and while giving Print_r, the output as follows,

 Array ( 
[pattern] => 
[status] => Array ( [0] => 0 [1] => 4 )
)

I have to pass the status value to one function like,

function value($action, $param){
// want to use the value here
}

how can i get the value here. please help

5
  • $param["status"] …? Commented Oct 9, 2017 at 13:49
  • print_r($param['status']); Commented Oct 9, 2017 at 13:50
  • function value($action, $param['status']){ } is this correct Commented Oct 9, 2017 at 13:54
  • try this function value($action, $param){ // want to use the value here print_r($param['status']); } Commented Oct 9, 2017 at 13:56
  • Thanks .. it is printing . but i want to use the values dynamically like, $status= $param['status'] Commented Oct 9, 2017 at 14:00

1 Answer 1

1

If you want to pass a multi-dimensional array as a parameter, simply pass the child array with the name of the parent (container array).

So if an array like

Array ( 
         [pattern] => 
         [status] => Array (
                             [0] => 0 
                             [1] => 4 
                           )
)

if you want both the elements of status to be passed into the function,pass the name of the array parent. (in this case, param)

function foo($x)
{
  echo "<pre>"; // just to make reading easy ;)
  print_r($x);
 }

The function foo() displays the contents passed into the function which you can use to see what's being passed.

so things like foo($param['status']) gives this :

Array( [0] => 0 [1]=> 4 )

and something like foo($param['status'][1]) gives this : 4

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.