Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference between -> and => in laravel

Tags:

laravel-5.2

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]);
like image 365
Anika Avatar asked Mar 24 '17 08:03

Anika


People also ask

What is the difference between -> and => in Laravel?

-> and => are both operators. The difference is that => is the assign operator that is used while creating an array.

What is the difference between => and -> in PHP?

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.

What does => mean in PHP?

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.

What does {{ }} mean in Laravel?

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.


Video Answer


2 Answers

-> 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

like image 106
Gohel Dhaval Avatar answered Sep 19 '22 10:09

Gohel Dhaval


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;
like image 28
Jure Jager Avatar answered Sep 18 '22 10:09

Jure Jager