What does foo[] mean in $this->foo[] in php [duplicate] - php

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 6 years ago.
Is foo[] an array?
In the following code is an array element being assigned to foo[]? And is there an array key that is automatically associated with it?
$this->foo[] = 'hello world';

This is adding an element to the end of the foo array.
It's the same as using array_push().

Related

Differences in this Array Declarations in PHP [duplicate]

This question already has answers here:
PHP array vs [ ] in method and variable declaration
(5 answers)
PHP: What's the difference between initializing an array with "new" vs without it?
(4 answers)
Closed 1 year ago.
What is the difference between declaring:
$myArray = Array();
and:
$myArray = [];
There's no difference, it's just two alternative syntaxes. See https://www.php.net/manual/en/language.types.array.php

making array with array() or []? - PHP [duplicate]

This question already has answers here:
Best way to initialize (empty) array in PHP
(9 answers)
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
PHP Difference between array() and []
(5 answers)
Closed 3 years ago.
in evey tutorial they said you should make an array with "array()" but I realize that I can also make it with "[]" what are the difference?
array() :
$a = array("red","blue","green");
[] :
$a = ["red","blue","green"];

What is the function of "&" right before the session variable? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 6 years ago.
$cart = &$_SESSION['journal_items']; anybody know when do we use the & symbol like that?
Basically it means that $cart won't get the value stored in $_SESSION['journal_items'], but it's reference. Whenever you call $cart, you'll be calling the current value of $_SESSION['journal_items'], even if it has been changed after this declaration.
Example:
$_SESSION['journal_items'] = "test";
$cart = &$_SESSION['journal_items'];
//$cart's current value is "test"
$_SESSION['journal_items'] = "test2";
//$cart's current value is "test2"
See this answer and this reference book.

What does -> mean in the context of this function call? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What does "->" mean/refer to in PHP? [duplicate]
(12 answers)
Closed 9 years ago.
$title = l(
$comment->subject,
comment_node_url(),
array('fragment' => "comment-$comment->cid")
);
Ok, so $title is the l() function, and from what I'm reading, I am passing the $comment->subject argument to l() - is that correct?
What does $comment->subject mean? I'm looking all over and not understanding what it means. Is it an operator of some sort?
Sorry if this is a simple question - I just can't find the answer anywhere.
It's just an operate that indicates that "subject" is a property of $comment. You can read a bit more on the PHP manual.

What is this operator "=>"? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What does “=>” mean in PHP?
Reference - What does this symbol mean in PHP?
I see this symbol in a lot of PHP code.
I can't figure out what it means or what it does..
Is it really an operator ?
Do you mean =>? If so, it's for initializing array keys (or indexes if you prefer). Like this:
$values = array(
'foo' => 'bar'
);
This will initiazlie an array with a key named foo with a value of bar.
Read more on about arrays at php.net.
http://php.net/manual/en/language.operators.php

Categories