Skip to content
Advertisement

Get the first element of my array $_POST[‘tableFields’]

I’m trying to get the first element of my asociative array $_POST['tableFields'].

print_r($_POST['tableFields']); // I get: ["id","usuario","apellido1","apellido2","email","password"]

I tryied using reset() method but doesn’t show anything.

$campo = reset($_POST['tableFields']);
print_r($campo); // This doesn't show anything.

Advertisement

Answer

It is JSON format so its a string value. You must do print_r(json_decode($_POST['tableFields'],1)[0]); or reset(json_decode($_POST['tableFields'],1));

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement