This is the code where we have used -> and => .
But I always get confused, while writing code at that time which one to use and where.
So seeking its logic to easily remember it.
$quan= $request->all();
ChaiExl::create(['date'=>date('Y-m-d',strtotime($quan['dt'])),'quantity'=>$quan['quan']]);
return view('edit',['row'=>$row]);
-> and => are both operators. The difference is that => is the assign operator that is used while creating an array.
Conclusion. The two operators, => and -> may look similar but are totally different in their usage. => is referred to as double arrow operator. It is an assignment operator used in associative arrays to assign values to the key-value pairs when creating arrays.
It means assign the key to $user and the variable to $pass. When you assign an array, you do it like this. $array = array("key" => "value"); It uses the same symbol for processing arrays in foreach statements. The '=>' links the key and the value.
By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax: Hello, {!! $name !!}. Follow this answer to receive notifications.
->
and =>
are both operators.
The difference is that =>
is the assign operator that is used while creating an array.
For example:
array(key => value, key2 => value2)
And
->
is the access operator. It accesses an object's value
This is PHP syntax, not laravel specifics.
=> is for setting values in arrays:
$foobar = array(
'bar' => 'something',
'foo' => 222
);
or
$foobar = [
'bar' => 'something',
'foo' => 222
];
-> is used for calling class methods and properties:
class MyClass {
public $bar = 'something';
public function foo() {
}
}
$foobar = new MyClass();
$foobar->foo();
echo $foobar->bar;
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