0

Noob question I guess... I just want to know what this sort of thing is called.

My guess is that acf_add_options_page is a function that's taking an array of values. I just want to know the name of these arrow things inside of an array is...

acf_add_options_page(array(
  'page_title'  => 'General Settings',
  'menu_title'  => 'General Settings',
  'position' => '63.3',
));
monsaic123
  • 241
  • 2
  • 11
  • 1
    php associative array.it help you store value in key value pair – John Lobo Jun 08 '21 at 07:31
  • 1
    Afaik, they are assignment operators. – M. Eriksson Jun 08 '21 at 07:32
  • 1
    This might help you a little: https://stackoverflow.com/questions/14037290/what-does-this-mean-in-php-or#:~:text=The%20double%20arrow%20operator%2C%20%3D%3E,corresponding%20index%20of%20an%20array. – Example person Jun 08 '21 at 07:50
  • Welcome to Stackoverflow! Please post a [minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), so that we can help you. – jhoepken Jun 08 '21 at 13:12

2 Answers2

1

This type of array is called an associative array. This helps you in a case where you need to define your own key as the index of the array. Let's say you want to print a users list where the User model/entity/table has the following column name:

  • name
  • email
  • phone

Rather than printing the array as $user[0] you can call it $user['name'] It's not only typed-friendly but also helps you to avoid collapse. There might be cases where email is retrieved before the name column. You are expecting something like this:

0 => 'John Doe',
1 => 'john@example.com',
2 => '0999999999'

But end up with something like this:

 0 => 'John Doe',
 1 => '0999999999',
 2 => 'john@example.com'

To avoid those cases you can print/access them by their key defined by you. In such cases, you don't have to follow the serial. Just print them according to their key name.

// no need to remember the index
"name"  => 'John Doe',
"phone" => '0999999999',
"email" => 'john@example.com'

For more you can give it a read: https://www.php.net/manual/en/language.types.array.php

Mehedi Hassan
  • 376
  • 3
  • 10
  • Based on the title: _"What are these arrows inside of an array called?"_, they are asking what the symbol `=>` are called, not what type of array it is. – M. Eriksson Jun 08 '21 at 08:13
-4

=> is called assignment operator. It is use to assign value on right hand side to the Key on the left hand side.

For example

“fname”=>“Alhaji” 
“age”=>“25”

They are use in associative array

Tom Solid
  • 2,226
  • 1
  • 13
  • 32