简体   繁体   中英

How do I store this array into MySQL?

below mentioned is a part of my total script and I want to store this value to MySQl

I dont know how to use implode function here!! can any one help me??

 $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)));

See this link: http://www.evolt.org/node/60222
All you have to do is: $serialized_country=serialize($country)
and then store the $serialized_country in your database.
And then when you retrieve the same from the database use something like:
$country=unserialize($serialized_country)

Hope that helps.... but keep in mind, if you have to retrieve this data many number of time repeatedly in your application, then you might have to bother about the overhead of serializing and unserializing the data each time.

为什么在存储它之前不使用serialize()将数组转换为字符串表示形式,而在检索它时却不使用unserialize()呢?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM