laravel-php, why do you use objects? Can't use arrays instead?

Source: Internet
Author: User
Is it like Laravel Orm can be done by using the query Builder?

Reply content:

Is it like Laravel Orm can be done by using the query Builder?

Is it not normal for PHP to save the result set of a SQL query with an array? How can you say you can't use an array?
The PDO Fetchall returned is an array:
$db->query('SELECT * FROM posts')->fetchAll(PDO::FETCH_ASSOC);
The PHP array is very flexible and can do a lot of things, even in SQL, such as sorting and grouping:


  Array (' gold ' = = 8, ' silver ' = + 3, ' bronze ' = + 6,), ' Russia ' + = Array (' Gold ' = ' 3 ', ' Silver ' = + 6, ' bronze ' = 3, ' us ' = + Array (' gold medal ' = 6, ' Silver ' + 8, ' bronze ' =& Gt         8,), ' australia ' = = Array (' gold medal ' = + 4, ' silver medal ' = 0, ' bronze ' = 4, '), ' italy ' = = Array ( ' Gold medal ' = 3, ' silver medal ' = 4, ' bronze ' = 2, ');//Implement ORDER Byforeach ($arr as $k + $v) {$so    rt[' Gold medal ' [$k] = $v [' Gold medal '];    $sort [' Silver medal '] [$k] = $v [' Silver medal ']; $sort [' bronze '] [$k] = $v [' Bronze Medal '];} Array_multisort ($sort [' Gold medal '], Sort_desc, $sort [' Silver medal '], Sort_desc, $sort [' Bronze medal '], Sort_desc, $arr); Var_export ($  ARR);//Implement GROUP by (see what values are in the ' Gold field ') $tmp = Array (), foreach ($arr as $k = = $v) {if (In_array ($v [' Gold '], $tmp) = = = FALSE)    {$tmp [] = $v [' Gold medal ']; }}var_export ($TMP);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.