开发者

Printing PHP Array into a string with correct syntax

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,
    );"    


Use var_export()[docs]:

$string = var_export($array, true);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜