I am wondering if there is something similar to javascript or VB's with
statement but in php
The way this works, for example in VB is shown below. The two code snippets do the same effect:
array[index].attr1 = val1;
array[index].attr2 = val2;
array[index].attr3 = val3;
is equal to :
With(array[index])
.attr1 = val1
.attr2 = val2
.attr3 = val3
End With
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
That's part of the printf method. Those are placeholders for the variables that follow. %d means treat it as a number. %s means treat it as a string. The list of variables that follow in the function call are used in the order they show up in the preceding string.
PHP Conditional Statements if statement - executes some code if one condition is true. if...else statement - executes some code if a condition is true and another code if that condition is false. if...elseif...else statement - executes different codes for more than two conditions.
Control statements are conditional statements that execute a block of statements if the condition is correct. The statement inside the conditional block will not execute until the condition is satisfied.
Not exactly the with statement, but you can use references in your example:
$r = &$array[index];
$r->attr1 = val1;
$r->attr2 = val2;
$r->attr3 = val3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With