Hello,
My question is how to use an alternative function, but does the same job, to print_r in php, especially to save values, not just to show it on the browser.

<?php
$a1=array("Dog","Dog","Cat");
$a2=array("Pluto","Fido","Missy");
array_multisort($a1,$a2);
print_r($a1);
print_r($a2);
?>

How can I save the results in a text document or other types of documents.

    zeer;10988516 wrote:

    My question is how to use an alternative function, but does the same job, to print_r in php

    One way would be to use a [man]foreach/man loop to iterate over the arrays and output the data in whatever format you'd like.

    zeer;10988516 wrote:

    especially to save values, not just to show it on the browser.

    Er... well that's a whole different issue altogether. See below.

    zeer;10988516 wrote:

    How can I save the results in a text document or other types of documents.

    The answer to both would be something like [man]file_put_contents/man (or [man]fopen[/man]/[man]fwrite[/man]/[man]fclose[/man] if you like punishing yourself with extra code).

      Use the optional 2nd arg to print_r():

      file_put_contents($fileName, print_r($array, true));
      
        NogDog;10988582 wrote:

        Use the optional 2nd arg to print_r():

        file_put_contents($fileName, print_r($array, true));
        

        A gem, indeed! Thank you, sir! 🙂

          Write a Reply...