如何在另一个php文件中打印数组值?

时间:2017-03-18 01:27:27

标签: php arrays

我在this page中有API结果 如何打印例如:在另一个php文件中,它的id = 68(第一个)(在这种情况下,每年价格是500000.00)的产品的每年价格? 这是whmcs的内部api。 谢谢

Array
(
  [result] => success
  [totalresults] => 4
  [products] => Array
    (
      [product] => Array
        (
          [0] => Array
            (
              [pid] => 68
              [gid] => 16
              [type] => hostingaccount
              [name] => IR-CL100
              [description] => <li>حجم دیسک<strong>۱۰۰ مگابایت</strong></li>
<li>ترنسفر ماهیانه<strong>۲ گیگابایت</strong></li>
<li>پارک دومین <strong>رایگان</strong></li>
<li>دومین افزوده<strong>۱۰/۰۰۰ تومان</strong></li>
<li>تعداد MySQL<strong>۱ عدد</strong></li>

              [module] => directadmin
              [paytype] => recurring
              [pricing] => Array
                (
                  [IRR] => Array
                    (
                      [prefix] => 
                      [suffix] =>  ریال
                      [msetupfee] => 100000.00
                      [qsetupfee] => 50000.00
                      [ssetupfee] => 0.00
                      [asetupfee] => 0.00
                      [bsetupfee] => 0.00
                      [tsetupfee] => 0.00
                      [monthly] => 50000.00
                      [quarterly] => 150000.00
                      [semiannually] => 300000.00
                      [annually] => 500000.00
                      [biennially] => 900000.00
                      [triennially] => -1.00
                    )

                )

              [customfields] => Array
                (
                  [customfield] => Array
                    (
                    )

                )

              [configoptions] => Array
                (
                  [configoption] => Array
                    (
                      [0] => Array
                        (
                          [id] => 31
                          [name] => سایت افزوده
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 59
                                      [name] => سایت افزوده - میزبانی بیش از یک سایت در یک حساب کاربری
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 10000.00
                                              [quarterly] => 30000.00
                                              [semiannually] => 60000.00
                                              [annually] => 100000.00
                                              [biennially] => 200000.00
                                              [triennially] => 300000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                      [1] => Array
                        (
                          [id] => 63
                          [name] => دیسک اضافی
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 166
                                      [name] => گیگابایت دیسک اضافی
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 100000.00
                                              [quarterly] => 300000.00
                                              [semiannually] => 600000.00
                                              [annually] => 1200000.00
                                              [biennially] => 2400000.00
                                              [triennially] => 3600000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                      [2] => Array
                        (
                          [id] => 33
                          [name] => پهنای باند اضافه
                          [type] => 4
                          [options] => Array
                            (
                              [option] => Array
                                (
                                  [0] => Array
                                    (
                                      [id] => 61
                                      [name] => ۱۰ گیگابایت ترنسفر ماهیانه برای سایت های پر بازدید
                                      [recurring] => 
                                      [pricing] => Array
                                        (
                                          [IRR] => Array
                                            (
                                              [msetupfee] => 50000.00
                                              [qsetupfee] => 0.00
                                              [ssetupfee] => 0.00
                                              [asetupfee] => 0.00
                                              [bsetupfee] => 0.00
                                              [tsetupfee] => 0.00
                                              [monthly] => 50000.00
                                              [quarterly] => 150000.00
                                              [semiannually] => 300000.00
                                              [annually] => 600000.00
                                              [biennially] => 1200000.00
                                              [triennially] => 1800000.00
                                            )

                                        )

                                    )

                                )

                            )

                        )

                    )

                )

            )

        )

    )

)

1 个答案:

答案 0 :(得分:0)

问题是您的API返回了print_r的内容,它应该返回JSON:

这样做:

header('Content-Type: application/json'); 
echo json_encode($array);