I\'m trying to use return in a ternary operator, but receive an error:
Parse error: syntax error, unexpected T_RETURN
Here\'s the code:
Plop,
if you want modify your return with ternary ?
it's totally possible.
In this exemple, i have a function with array in parameters. This exemple function is used to parse users array. On return i have an array with user id and user username. But what happens if I do not have any users?
<?php
public funtion parseUserTable(array $users) {
$results = [];
foreach ($users as $user) {
$results[$users['id']] = $user['username'];
}
return $results ?: array('false', $e, "No users on table."); // Ternary operator.
}
Sorry for my bad english, i'm french user haha.
N-D.