数组中的变量(返回null)[关闭]

I cannot seem to be able to use the variable into the array. It must be a syntax error.

Please, help me sort this out.

$id=$_POST['eventid'];
$data = array('message' => $id);

$id content is null.

Thanks.

Your coding is nice except the $_POST value is not getting fetched. I have commented the POST var just to make sure your code works fine.

<?php

$id='test';//$_POST['eventid'];
$data = array('message' => $id);

print_r($data);//output : Array ( [message] => test )
?>
$id = $_POST['eventid'];
$data = array('message' => $id);

If $id is null, it means that $_POST['eventid'] is null.

Also, are you sure that it is actually null, and not a blank string? Because there's a slight difference between the two.

My guess is that $_POST['eventid'] does not exist or the value is an empty string.