21

If I have this array:

<?php 

$myarray =  Array
                (
                        'keyword' => 'seo',
                        'title_factor' => false,
                        'description_factor' => false,
                        'headtags_factor' => false,
                        'imgalt_factor' => false,
                        'keyword_density' => 0,
                );


var_dump($myarray);
print_r($myarray);                      


?>

Here is the output of vardump and print_r:

array(6) {
  ["keyword"]=>
  string(3) "seo"
  ["title_factor"]=>
  bool(false)
  ["description_factor"]=>
  bool(false)
  ["headtags_factor"]=>
  bool(false)
  ["imgalt_factor"]=>
  bool(false)
  ["keyword_density"]=>
  int(0)
}
Array
(
    [keyword] => 'seo'
    [title_factor] => 
    [description_factor] => 
    [headtags_factor] => 
    [imgalt_factor] => 
    [keyword_density] => 0
)

Here is what I want as output:

    "Array
    (
            'keyword' => 'seo',
            'title_factor' => false,
            'description_factor' => false,
            'headtags_factor' => false,
            'imgalt_factor' => false,
            'keyword_density' => 0,
    );"    
2
  • As seo does not seem to be a constant, you should change 'keyword' => seo, to 'keyword' => 'seo',. Commented Sep 6, 2011 at 8:21
  • @str I will edit my post, seo should be a string. Commented Sep 6, 2011 at 8:37

2 Answers 2

43

Use var_export()[docs]:

$string = var_export($array, true);
Sign up to request clarification or add additional context in comments.

Comments

6

You're searching for var_export if I'm correct

more info about var_export at http://www.php.net/manual/en/function.var-export.php

1 Comment

didn't get a warning there was an answer as i answered only a few seconds later ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.