Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if statement within array

I have the following PHP array

$menu['Settings']['user'] = array(
    1 => 'General',
    'database.php' => 'Database',
    'users.php' => 'User Management'
);

However the entry for database.php needs to depend on if a string called $user == "Admin"

Any idea how I can put an if statement inside this array?

like image 852
John Smith Avatar asked Jul 30 '26 11:07

John Smith


1 Answers

Use a ternary operation?

'database.php' => $user === 'Admin' ? 'Database' : 'Grumblecakes',
like image 153
kojiro Avatar answered Aug 02 '26 01:08

kojiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!