Php 多维SEO数组,如何提取和打印所有?

Php 多维SEO数组,如何提取和打印所有?,php,arrays,multidimensional-array,foreach,Php,Arrays,Multidimensional Array,Foreach,我正在为我的应用程序开发一个seo“插件”,我设法创建所需的阵列。。。但当我尝试执行foreach循环时,它什么也不输出。。。没有错误,可能是foreach循环中的foreach循环 我的PHP代码: include 'seo.class.php'; $SEO = new SEO(); $SEO->Set("Image", "img.png"); $SEO->Set("Description", "My description"); $SEO->Set("PageTitle"

我正在为我的应用程序开发一个seo“插件”,我设法创建所需的阵列。。。但当我尝试执行foreach循环时,它什么也不输出。。。没有错误,可能是foreach循环中的foreach循环

我的PHP代码:

include 'seo.class.php';

$SEO = new SEO();
$SEO->Set("Image", "img.png");
$SEO->Set("Description", "My description");
$SEO->Set("PageTitle", "Page Title");
$SEO->Set("Author", "Author");
$SEO->build();
?>

<html>
    <head>
       <?php echo $SEO->render($SEO->Array); ?>
    </head>
</html>
改变

foreach($Meta[1]作为$Property=>$Value){
$R.=“更改

foreach($Meta[1]作为$Property=>$Value){

$R.=“指定
$Meta['content']
而不是
$Meta[1]

另外,您可能对使用PHP的magic
\uuu set()
方法感兴趣,而不是基本上用set()方法重新实现它。您可以在PHPDoc中定义支持的@properties


指定
$Meta['content']
而不是
$Meta[1]

另外,您可能对使用PHP的magic
\uuu set()
方法感兴趣,而不是基本上用set()方法重新实现它。您可以在PHPDoc中定义支持的@properties

class SEO{

    public $SiteName = "Website Name";


    public $Author;
    public $BaseUrl;
    public $PageUrl;
    public $PageTitle;
    public $Description;
    public $Image;
    public $Array;


    function Set($What, $Value){
        $this->$What = $Value;
    }


    function build(){
        $SEO = array();

        //For twitter:
        $SEO['Twitter'] = array(

            'type' => 'name', 
            'content' => array(

            'twitter:description' => $this->Description,
            'twitter:title' => $this->PageTitle,
            'twitter:image' => $this->Image,
            'twitter:creator' => $this->Author )
            );

        //For facebok:
        $SEO['Facebook'] = array(

            'type' => 'property', 
            'content' => array(

            'og_title' => $this->PageTitle,
            'og:description' => $this->Description,
            'og:type' => "article",
            'og:url' => $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
            'og:image' => $this->Image,
            'og:site_name' => $this->SiteName )
        );



        $this->Array = $SEO;   
    }

    function render($Array){

        foreach($Array as $Location => $Meta){


            foreach($Meta[1] as $Property => $Value){
                $R .= "<meta ".$Type.'="'.$Property.'" content="'.$Value.'"/>';
            }  
        }

        return $R;
    }
}
Array
(
    [Twitter] => Array
        (
            [type] => name
            [content] => Array
                (
                    [twitter:description] => My description
                    [twitter:title] => Page Title
                    [twitter:image] => img.png
                    [twitter:creator] => Author
                )

        )

    [Facebook] => Array
        (
            [type] => property
            [content] => Array
                (
                    [og_title] => Page Title
                    [og:description] => My description
                    [og:type] => article
                    [og:url] => localhost/seotest.php
                    [og:image] => img.png
                    [og:site_name] => Website Name
                )

        )

)
            foreach($Meta[1] as $Property => $Value){
                $R .= "<meta ".$Type.'="'.$Property.'" content="'.$Value.'"/>';
            }
            foreach($Meta[0] as $Property => $Value){
                $R .= "<meta ".$Type.'="'.$Property.'" content="'.$Value.'"/>';
            }