Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With statement in php

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
like image 867
Dany Khalife Avatar asked Nov 13 '11 02:11

Dany Khalife


People also ask

What does ?: Mean in PHP?

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.

What does %d mean in PHP?

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.

What is conditional statement in PHP?

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.

What are control statements in PHP?

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.


1 Answers

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;
like image 113
fardjad Avatar answered Oct 03 '22 01:10

fardjad