PHP - Many variables or One array?

后端 未结 6 856
半阙折子戏
半阙折子戏 2020-12-14 08:52

I have a question, what is more faster ...

  1. I make many variables that contain all of my data, or
  2. I make one array in one variable that contai
6条回答
  •  不知归路
    2020-12-14 09:31

    Just a try :)

    Test 1

    With 5 variables

    $myvar1 = 'hello';
    $myvar2 = 'hello';
    $myvar3 = 'hello';
    $myvar4 = 'hello';
    $myvar4 = 'hello';
    
    print_r(memory_get_usage());
    

    Resut : 618600

    Test 2

    with 5 array keys

    $myvar = array();
    $myvar['var1'] = 'hello';
    $myvar['var2'] = 'hello';
    $myvar['var3'] = 'hello';
    $myvar['var4'] = 'hello';
    $myvar['var5'] = 'hello';
    
    print_r(memory_get_usage());
    

    Resut : 620256

提交回复
热议问题