Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$data = array() vs unset($array)

this is my first question.

I am doing some optimizations on a php script, improving its speed of execution...

Between :

$datas = array();
$datas['file_import'] = $file_name_reporting;

And :

unset($datas);
$datas['file_import'] = $file_name_reporting;

Can someone tell me which one is faster ?

Thank you

like image 839
user1242440 Avatar asked Apr 03 '26 03:04

user1242440


1 Answers

Your second example causes warning, because $datas is right now null and you are treating it as an array, so you have to declare it as an empty array before.

So just follow your first example - assign an empty array and then put into it some data.

like image 71
hsz Avatar answered Apr 08 '26 04:04

hsz