What is the best way to unload a PHP array into html table





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I want to print customerdata via PHP (in table). Only I run into the problem that it must come from two different web stores (a dual array). The first webshop has a customer and the other two.



This code is retrieved by a connection via the woocommerce API.
Firstly I connect to the database getting all "Woocommerce Stores"



$webshops = DB::table('webshops')->get();
$costumerdata = array();


Then I loop trought the data to get all data



foreach ($webshops as $webshop => $value) {
$wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
// array_push($costumerlist, $wc_api->get_customers());
foreach ($wc_api->get_customers() as $costumer) {
array_push($costumerdata, $costumer);
}
}


When I throw a DD over the data,



dd($costumerdata);


The next data is returned from the script. Now I want to put this array in an HTML / PHP list. How do I turn a whole list of all the customers in a table (I think I do not the loop properly).



array:2 [▼
0 => array:1 [▼
0 => {#252 ▼
+"id": 2
+"created_at": "2018-11-22T14:29:01Z"
+"email": "TheScruffieSpadexMuffin@gmail.cop"
+"first_name": "Bernardo"
+"last_name": "Mcscrufflemuffle"
+"username": "thescruffiespadexmuffin"
+"role": "customer"
+"last_order_id": 21
+"last_order_date": "2018-11-22T14:29:01Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/57918972c32605a2acc4d15771f09f69?s=96&d=mm&r=g"
+"billing_address": {#253 ▶}
+"shipping_address": {#254 ▶}
}
]
1 => array:2 [▼
0 => {#245 ▼
+"id": 3
+"created_at": "2018-11-22T17:48:21Z"
+"email": "info@xxx-it.nl"
+"first_name": "Bladieblabla"
+"last_name": "Vla"
+"username": "info"
+"role": "customer"
+"last_order_id": 28
+"last_order_date": "2018-11-23T10:08:06Z"
+"orders_count": 2
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/ba4da010e0ff01978cdf0d3e176dfcea?s=96&d=mm&r=g"
+"billing_address": {#256 ▶}
+"shipping_address": {#257 ▶}
}
1 => {#258 ▼
+"id": 4
+"created_at": "2018-11-23T10:10:48Z"
+"email": "asdaasd@xxx-it.nl"
+"first_name": "Lyla"
+"last_name": "Futurama"
+"username": "asdaasd"
+"role": "customer"
+"last_order_id": 29
+"last_order_date": "2018-11-23T10:10:49Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/a4626c2ac8236e09229e3599d0302c84?s=96&d=mm&r=g"
+"billing_address": {#259 ▶}
+"shipping_address": {#260 ▶}
}
]
]


Thank you :)










share|improve this question

























  • You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

    – Matthew Daly
    Nov 23 '18 at 11:14











  • Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

    – Mesuti
    Nov 23 '18 at 11:18











  • Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

    – RiggsFolly
    Nov 23 '18 at 11:22




















1















I want to print customerdata via PHP (in table). Only I run into the problem that it must come from two different web stores (a dual array). The first webshop has a customer and the other two.



This code is retrieved by a connection via the woocommerce API.
Firstly I connect to the database getting all "Woocommerce Stores"



$webshops = DB::table('webshops')->get();
$costumerdata = array();


Then I loop trought the data to get all data



foreach ($webshops as $webshop => $value) {
$wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
// array_push($costumerlist, $wc_api->get_customers());
foreach ($wc_api->get_customers() as $costumer) {
array_push($costumerdata, $costumer);
}
}


When I throw a DD over the data,



dd($costumerdata);


The next data is returned from the script. Now I want to put this array in an HTML / PHP list. How do I turn a whole list of all the customers in a table (I think I do not the loop properly).



array:2 [▼
0 => array:1 [▼
0 => {#252 ▼
+"id": 2
+"created_at": "2018-11-22T14:29:01Z"
+"email": "TheScruffieSpadexMuffin@gmail.cop"
+"first_name": "Bernardo"
+"last_name": "Mcscrufflemuffle"
+"username": "thescruffiespadexmuffin"
+"role": "customer"
+"last_order_id": 21
+"last_order_date": "2018-11-22T14:29:01Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/57918972c32605a2acc4d15771f09f69?s=96&d=mm&r=g"
+"billing_address": {#253 ▶}
+"shipping_address": {#254 ▶}
}
]
1 => array:2 [▼
0 => {#245 ▼
+"id": 3
+"created_at": "2018-11-22T17:48:21Z"
+"email": "info@xxx-it.nl"
+"first_name": "Bladieblabla"
+"last_name": "Vla"
+"username": "info"
+"role": "customer"
+"last_order_id": 28
+"last_order_date": "2018-11-23T10:08:06Z"
+"orders_count": 2
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/ba4da010e0ff01978cdf0d3e176dfcea?s=96&d=mm&r=g"
+"billing_address": {#256 ▶}
+"shipping_address": {#257 ▶}
}
1 => {#258 ▼
+"id": 4
+"created_at": "2018-11-23T10:10:48Z"
+"email": "asdaasd@xxx-it.nl"
+"first_name": "Lyla"
+"last_name": "Futurama"
+"username": "asdaasd"
+"role": "customer"
+"last_order_id": 29
+"last_order_date": "2018-11-23T10:10:49Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/a4626c2ac8236e09229e3599d0302c84?s=96&d=mm&r=g"
+"billing_address": {#259 ▶}
+"shipping_address": {#260 ▶}
}
]
]


Thank you :)










share|improve this question

























  • You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

    – Matthew Daly
    Nov 23 '18 at 11:14











  • Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

    – Mesuti
    Nov 23 '18 at 11:18











  • Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

    – RiggsFolly
    Nov 23 '18 at 11:22
















1












1








1








I want to print customerdata via PHP (in table). Only I run into the problem that it must come from two different web stores (a dual array). The first webshop has a customer and the other two.



This code is retrieved by a connection via the woocommerce API.
Firstly I connect to the database getting all "Woocommerce Stores"



$webshops = DB::table('webshops')->get();
$costumerdata = array();


Then I loop trought the data to get all data



foreach ($webshops as $webshop => $value) {
$wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
// array_push($costumerlist, $wc_api->get_customers());
foreach ($wc_api->get_customers() as $costumer) {
array_push($costumerdata, $costumer);
}
}


When I throw a DD over the data,



dd($costumerdata);


The next data is returned from the script. Now I want to put this array in an HTML / PHP list. How do I turn a whole list of all the customers in a table (I think I do not the loop properly).



array:2 [▼
0 => array:1 [▼
0 => {#252 ▼
+"id": 2
+"created_at": "2018-11-22T14:29:01Z"
+"email": "TheScruffieSpadexMuffin@gmail.cop"
+"first_name": "Bernardo"
+"last_name": "Mcscrufflemuffle"
+"username": "thescruffiespadexmuffin"
+"role": "customer"
+"last_order_id": 21
+"last_order_date": "2018-11-22T14:29:01Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/57918972c32605a2acc4d15771f09f69?s=96&d=mm&r=g"
+"billing_address": {#253 ▶}
+"shipping_address": {#254 ▶}
}
]
1 => array:2 [▼
0 => {#245 ▼
+"id": 3
+"created_at": "2018-11-22T17:48:21Z"
+"email": "info@xxx-it.nl"
+"first_name": "Bladieblabla"
+"last_name": "Vla"
+"username": "info"
+"role": "customer"
+"last_order_id": 28
+"last_order_date": "2018-11-23T10:08:06Z"
+"orders_count": 2
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/ba4da010e0ff01978cdf0d3e176dfcea?s=96&d=mm&r=g"
+"billing_address": {#256 ▶}
+"shipping_address": {#257 ▶}
}
1 => {#258 ▼
+"id": 4
+"created_at": "2018-11-23T10:10:48Z"
+"email": "asdaasd@xxx-it.nl"
+"first_name": "Lyla"
+"last_name": "Futurama"
+"username": "asdaasd"
+"role": "customer"
+"last_order_id": 29
+"last_order_date": "2018-11-23T10:10:49Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/a4626c2ac8236e09229e3599d0302c84?s=96&d=mm&r=g"
+"billing_address": {#259 ▶}
+"shipping_address": {#260 ▶}
}
]
]


Thank you :)










share|improve this question
















I want to print customerdata via PHP (in table). Only I run into the problem that it must come from two different web stores (a dual array). The first webshop has a customer and the other two.



This code is retrieved by a connection via the woocommerce API.
Firstly I connect to the database getting all "Woocommerce Stores"



$webshops = DB::table('webshops')->get();
$costumerdata = array();


Then I loop trought the data to get all data



foreach ($webshops as $webshop => $value) {
$wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
// array_push($costumerlist, $wc_api->get_customers());
foreach ($wc_api->get_customers() as $costumer) {
array_push($costumerdata, $costumer);
}
}


When I throw a DD over the data,



dd($costumerdata);


The next data is returned from the script. Now I want to put this array in an HTML / PHP list. How do I turn a whole list of all the customers in a table (I think I do not the loop properly).



array:2 [▼
0 => array:1 [▼
0 => {#252 ▼
+"id": 2
+"created_at": "2018-11-22T14:29:01Z"
+"email": "TheScruffieSpadexMuffin@gmail.cop"
+"first_name": "Bernardo"
+"last_name": "Mcscrufflemuffle"
+"username": "thescruffiespadexmuffin"
+"role": "customer"
+"last_order_id": 21
+"last_order_date": "2018-11-22T14:29:01Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/57918972c32605a2acc4d15771f09f69?s=96&d=mm&r=g"
+"billing_address": {#253 ▶}
+"shipping_address": {#254 ▶}
}
]
1 => array:2 [▼
0 => {#245 ▼
+"id": 3
+"created_at": "2018-11-22T17:48:21Z"
+"email": "info@xxx-it.nl"
+"first_name": "Bladieblabla"
+"last_name": "Vla"
+"username": "info"
+"role": "customer"
+"last_order_id": 28
+"last_order_date": "2018-11-23T10:08:06Z"
+"orders_count": 2
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/ba4da010e0ff01978cdf0d3e176dfcea?s=96&d=mm&r=g"
+"billing_address": {#256 ▶}
+"shipping_address": {#257 ▶}
}
1 => {#258 ▼
+"id": 4
+"created_at": "2018-11-23T10:10:48Z"
+"email": "asdaasd@xxx-it.nl"
+"first_name": "Lyla"
+"last_name": "Futurama"
+"username": "asdaasd"
+"role": "customer"
+"last_order_id": 29
+"last_order_date": "2018-11-23T10:10:49Z"
+"orders_count": 1
+"total_spent": "0.00"
+"avatar_url": "https://secure.gravatar.com/avatar/a4626c2ac8236e09229e3599d0302c84?s=96&d=mm&r=g"
+"billing_address": {#259 ▶}
+"shipping_address": {#260 ▶}
}
]
]


Thank you :)







php laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 11:10







Daansk44

















asked Nov 23 '18 at 11:06









Daansk44Daansk44

7210




7210













  • You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

    – Matthew Daly
    Nov 23 '18 at 11:14











  • Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

    – Mesuti
    Nov 23 '18 at 11:18











  • Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

    – RiggsFolly
    Nov 23 '18 at 11:22





















  • You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

    – Matthew Daly
    Nov 23 '18 at 11:14











  • Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

    – Mesuti
    Nov 23 '18 at 11:18











  • Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

    – RiggsFolly
    Nov 23 '18 at 11:22



















You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

– Matthew Daly
Nov 23 '18 at 11:14





You should look at Laravel's collections for this use case. You can use the each() method to loop through items and the map() method to return just the data you need.

– Matthew Daly
Nov 23 '18 at 11:14













Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

– Mesuti
Nov 23 '18 at 11:18





Whats you meaning with "unload into html"? You can iterate the values at your template and just echo some values?

– Mesuti
Nov 23 '18 at 11:18













Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

– RiggsFolly
Nov 23 '18 at 11:22







Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers

– RiggsFolly
Nov 23 '18 at 11:22














2 Answers
2






active

oldest

votes


















1














Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers



foreach ($webshops as $webshop => $value) {
$wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
foreach ($wc_api->get_customers() as $costumers) {
foreach ($customers as $customer) {
$costumerdata = $customer;
}
}
}



Also its more efficient to do $costumerdata = $costumer; than use array_push() if you are only adding one item to the array at a time, as you remove the overhead of calling a function.







share|improve this answer































    1














    the quick'n lazy way is to just throw it out there formatted by printf or JSON_PRETTY_PRINT, and just remember to html-encode the output, eg



    echo '<pre>';
    echo htmlentities(print_r($costumerdata,true), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
    echo '</pre>';


    or



    echo '<pre>';
    echo htmlentities(json_encode($costumerdata,JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_LINE_TERMINATORS), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
    echo '</pre>';


    wouldn't surprise me if laravel has something fancy built-in to do the same, but i'm not aware of it. (and i don't know laravel in general, but i know PHP.)



    ps, JSON_UNESCAPED_LINE_TERMINATORS is first introduced in PHP7.1, if your code needs to be compatible with older versions of PHP, you should add a



    if(!defined("JSON_UNESCAPED_LINE_TERMINATORS")){
    define("JSON_UNESCAPED_LINE_TERMINATORS",0);
    }


    before using it. (prior to 7.1, JSON_UNESCAPED_LINE_TERMINATORS was always on by default and impossible to disable)






    share|improve this answer


























    • Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

      – Daansk44
      Nov 23 '18 at 11:25














    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445536%2fwhat-is-the-best-way-to-unload-a-php-array-into-html-table%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers



    foreach ($webshops as $webshop => $value) {
    $wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
    foreach ($wc_api->get_customers() as $costumers) {
    foreach ($customers as $customer) {
    $costumerdata = $customer;
    }
    }
    }



    Also its more efficient to do $costumerdata = $costumer; than use array_push() if you are only adding one item to the array at a time, as you remove the overhead of calling a function.







    share|improve this answer




























      1














      Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers



      foreach ($webshops as $webshop => $value) {
      $wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
      foreach ($wc_api->get_customers() as $costumers) {
      foreach ($customers as $customer) {
      $costumerdata = $customer;
      }
      }
      }



      Also its more efficient to do $costumerdata = $costumer; than use array_push() if you are only adding one item to the array at a time, as you remove the overhead of calling a function.







      share|improve this answer


























        1












        1








        1







        Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers



        foreach ($webshops as $webshop => $value) {
        $wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
        foreach ($wc_api->get_customers() as $costumers) {
        foreach ($customers as $customer) {
        $costumerdata = $customer;
        }
        }
        }



        Also its more efficient to do $costumerdata = $costumer; than use array_push() if you are only adding one item to the array at a time, as you remove the overhead of calling a function.







        share|improve this answer













        Looks like you need another inner foreach to loop over $customer. As it seems like $wc_api->get_customers() returns an array of customers



        foreach ($webshops as $webshop => $value) {
        $wc_api = new WC_API_Client($value->WEBSHOP_CONSUMER_KEY, $value->WEBSHOP_CONSUMER_SECRET, $value->WEBSHOP_URL);
        foreach ($wc_api->get_customers() as $costumers) {
        foreach ($customers as $customer) {
        $costumerdata = $customer;
        }
        }
        }



        Also its more efficient to do $costumerdata = $costumer; than use array_push() if you are only adding one item to the array at a time, as you remove the overhead of calling a function.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 11:25









        RiggsFollyRiggsFolly

        72.1k1867113




        72.1k1867113

























            1














            the quick'n lazy way is to just throw it out there formatted by printf or JSON_PRETTY_PRINT, and just remember to html-encode the output, eg



            echo '<pre>';
            echo htmlentities(print_r($costumerdata,true), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            or



            echo '<pre>';
            echo htmlentities(json_encode($costumerdata,JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_LINE_TERMINATORS), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            wouldn't surprise me if laravel has something fancy built-in to do the same, but i'm not aware of it. (and i don't know laravel in general, but i know PHP.)



            ps, JSON_UNESCAPED_LINE_TERMINATORS is first introduced in PHP7.1, if your code needs to be compatible with older versions of PHP, you should add a



            if(!defined("JSON_UNESCAPED_LINE_TERMINATORS")){
            define("JSON_UNESCAPED_LINE_TERMINATORS",0);
            }


            before using it. (prior to 7.1, JSON_UNESCAPED_LINE_TERMINATORS was always on by default and impossible to disable)






            share|improve this answer


























            • Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

              – Daansk44
              Nov 23 '18 at 11:25


















            1














            the quick'n lazy way is to just throw it out there formatted by printf or JSON_PRETTY_PRINT, and just remember to html-encode the output, eg



            echo '<pre>';
            echo htmlentities(print_r($costumerdata,true), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            or



            echo '<pre>';
            echo htmlentities(json_encode($costumerdata,JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_LINE_TERMINATORS), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            wouldn't surprise me if laravel has something fancy built-in to do the same, but i'm not aware of it. (and i don't know laravel in general, but i know PHP.)



            ps, JSON_UNESCAPED_LINE_TERMINATORS is first introduced in PHP7.1, if your code needs to be compatible with older versions of PHP, you should add a



            if(!defined("JSON_UNESCAPED_LINE_TERMINATORS")){
            define("JSON_UNESCAPED_LINE_TERMINATORS",0);
            }


            before using it. (prior to 7.1, JSON_UNESCAPED_LINE_TERMINATORS was always on by default and impossible to disable)






            share|improve this answer


























            • Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

              – Daansk44
              Nov 23 '18 at 11:25
















            1












            1








            1







            the quick'n lazy way is to just throw it out there formatted by printf or JSON_PRETTY_PRINT, and just remember to html-encode the output, eg



            echo '<pre>';
            echo htmlentities(print_r($costumerdata,true), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            or



            echo '<pre>';
            echo htmlentities(json_encode($costumerdata,JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_LINE_TERMINATORS), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            wouldn't surprise me if laravel has something fancy built-in to do the same, but i'm not aware of it. (and i don't know laravel in general, but i know PHP.)



            ps, JSON_UNESCAPED_LINE_TERMINATORS is first introduced in PHP7.1, if your code needs to be compatible with older versions of PHP, you should add a



            if(!defined("JSON_UNESCAPED_LINE_TERMINATORS")){
            define("JSON_UNESCAPED_LINE_TERMINATORS",0);
            }


            before using it. (prior to 7.1, JSON_UNESCAPED_LINE_TERMINATORS was always on by default and impossible to disable)






            share|improve this answer















            the quick'n lazy way is to just throw it out there formatted by printf or JSON_PRETTY_PRINT, and just remember to html-encode the output, eg



            echo '<pre>';
            echo htmlentities(print_r($costumerdata,true), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            or



            echo '<pre>';
            echo htmlentities(json_encode($costumerdata,JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_LINE_TERMINATORS), ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
            echo '</pre>';


            wouldn't surprise me if laravel has something fancy built-in to do the same, but i'm not aware of it. (and i don't know laravel in general, but i know PHP.)



            ps, JSON_UNESCAPED_LINE_TERMINATORS is first introduced in PHP7.1, if your code needs to be compatible with older versions of PHP, you should add a



            if(!defined("JSON_UNESCAPED_LINE_TERMINATORS")){
            define("JSON_UNESCAPED_LINE_TERMINATORS",0);
            }


            before using it. (prior to 7.1, JSON_UNESCAPED_LINE_TERMINATORS was always on by default and impossible to disable)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 11:26

























            answered Nov 23 '18 at 11:20









            hanshenrikhanshenrik

            10.5k21841




            10.5k21841













            • Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

              – Daansk44
              Nov 23 '18 at 11:25





















            • Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

              – Daansk44
              Nov 23 '18 at 11:25



















            Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

            – Daansk44
            Nov 23 '18 at 11:25







            Thank you for the reply. But I am still stick at one thing. How can a loop throught the data so I get the correct data back using a for loop

            – Daansk44
            Nov 23 '18 at 11:25




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445536%2fwhat-is-the-best-way-to-unload-a-php-array-into-html-table%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy