Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference key from same array

I'm trying to reference the key/value pair of an item in the same array:

$glossary_args = array(
    'name'          => 'Glossary Terms',
    'singular_name' => 'Glossary Term',
    'add_new'       => 'Add New Term',
    'edit_item'     => 'Edit Term',
    'search_items'  => 'Search'.$glossary_args["name"],
)

Is this even possible? If so, how?

like image 581
Greg Wiley Avatar asked Nov 30 '22 05:11

Greg Wiley


1 Answers

You can use the fact that assignment is itself an expression in PHP:

$glossary_args = array(
    'name'          => ($name = 'Glossary Terms'),
    'singular_name' => 'Glossary Term',
    'add_new'       => 'Add New Term',
    'edit_item'     => 'Edit Term',
    'search_items'  => 'Search'.$name
)
like image 149
Eric Avatar answered Dec 06 '22 10:12

Eric