• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

How to convert an array to PHP variables ?


I would like to request an assistant.

I have the script as follows :

$package_array = get_hosting($cpid);

It produce the following array :

    [hid] => 2
    [hownerid] => admin
    [huser] => dsg462
    [hpass] => dsfserw354
    [horder_id] =>
    [hpackage_id] => 211436549
    [hplan] => Linux-Standard-Plan
    [hterm] => Annually
    [hstatus] => 1
    [hserver] => Server8
    [hfqdn] =>
    [serverip] =>
    [hip] =>
    [hdns1] => dns60.domain.com
    [hdns2] => dns61.domain.com
    [hdns3] =>
    [hdns4] =>
    [hdomain] => shamutest.com
    [hrenew_date] => 09-29-2014
    [hstart_date] => 09-29-2013
    [hrenewed_on] => 09-29-2013
    [hlast_invoice] =>
    [hprice_override] =>
    [hprice_override_expires] =>

May i know how to convert this array to variables ?

Eg :

echo "$hownerid"; , will give output as :


Appreciates any assistant.

Thank you.
  • 2
1 Solution
Ray PaseurCommented:
<?php echo $package_array['hownerid'];
Ray PaseurCommented:
You can assign the array indexes to variables with extract() but there are a variety of reasons why that is a risky programming practice.  It's smarter to just address the array elements directly and not risk the proliferation of variables into your symbol table.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now