Jump to content

array in function


felito

Recommended Posts

obviously that know that i can do

 

$var1 = $form_data_array["ensino"];
function livre($var1) {

}

 

 

i serialize an array and now i need to get the values, basically i want to reduce some lines of code, because i have much variables from serialize.

 

so, the correct syntax is:

 

function livre($form_data_array) {
$form_data_array["ensino"];

}

 

 

correct?

Link to comment
https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224085
Share on other sites

Are you trying to define the function, or call it? If you're defining it, just use a standard variable name for the argument. Use the array element when you call the function.

 

$array = range( 1, 25 );

function check_array($input) {
     if( is_array($input) ) {
          return "Array";
     } else {
          return "Not array";
     }
}

echo check_array( $array );
echo '<br>';
echo check_array( $array[5] );

Link to comment
https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224097
Share on other sites

$form_data_array = array();
$form_data_array = $_POST['myformdata']; 
echo $form_data_array["age"]; //display age correctly 

function check($form_data_array) { 
if (empty($form_data_array["age"])){
echo ("empty");
}
else 
echo ("not empty");

}

 

I need to check if the $form_data_array["age"]; is empty or no

Link to comment
https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224102
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.