Dear all.
how can I put my output array into file exactly as it appear below:

Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
        )

    [1] => Array
        (
            [0] => c
            [1] => d
        )

    [2] => Array
        (
            [0] => e
        )

)

How's this:

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

print_r($finalarr);

?>

I know, but I told that I wanna put this figure into file.
This is stored in the file:

Array( [a] => Array([b] => aa)[c] => Array([d] => Array([0] => e[1] => f))

I want to store it on file exactly appear below:(figure is important)

Array
(
    [a] => Array
        (
            [b] => e
        )

    [c] => Array
        (
            [d] => Array
                (
                    [0] => f
                    [1] => g
                )

        )

)

Do you mean the formatting? If that's the case, then use...

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

$lines = print_r($finalarr);
$filename = 'test.txt';

if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
   }

   if (fwrite($handle, $lines) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
}

?>

If you're wanting it to look like this as screen output, then:

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

$lines = print_r($finalarr);
?>
<pre><?php echo $lines; ?></pre>

Another 2¢. Hopes this helps more. :)

Do you mean the formatting? If that's the case, then use...

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

$lines = print_r($finalarr);
$filename = 'test.txt';

if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
   }

   if (fwrite($handle, $lines) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
}

?>

If you're wanting it to look like this as screen output, then:

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

$lines = print_r($finalarr);
?>
<pre><?php echo $lines; ?></pre>

Another 2¢. Hopes this helps more. :)

Did you test your code?
$line = print_r($finalarr); will out "1"

Did you test your code?
$line = print_r($finalarr); will out "1"

Sorry about that, lack of sleep. :)

<?php

$arr1 = array('a','b');
$arr2 = array('c','d');
$arr3 = array('e');

$finalarr = array($arr1,$arr2,$arr3);

?>
<pre><?php print_r($finalarr); ?></pre>

Tested. 2¢ more. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.