0

Hi how do I store this array to two different variables instead of echo??

$countries = array();
foreach ($my_data as $node)
{
    foreach($node->getElementsByTagName('a') as $href)
    {
        preg_match('/([0-9\.\%]+)/',$node->nodeValue, $match);
        $countries[trim($href->nodeValue)] = $match[0]; 
    }
}    

foreach ($countries as $country => $percent) echo str_replace("Â","",(strip_tags($country))) . ' - ' . str_replace("Â","",(strip_tags($percent)));

This will output

USA - 75%
UK - 65%
AU - 56%
UAE - 52%

and so on What I am looking is I need this array to store in multiple variable for example

$datac = USA,UK,AU,UAE

$datap = 75%,65%,56%,52%

like that any idea?

1
  • Your replacing is destroying your data. Commented Dec 18, 2010 at 4:48

1 Answer 1

2
$datac = array();
$datap = array();

foreach($countries as $country => $percent) {
    $datac[] = str_replace("Â","",(strip_tags($country)));
    $datap[] = str_replace("Â","",(strip_tags($percent)));
}

If you want them as strings, you can just do:

$datac = implode(',', $datac);
$datap = implode(',', $datap);

Reference: implode

Sign up to request clarification or add additional context in comments.

Comments

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.