Jump to content


Photo

Array values as variables


  • Please log in to reply
1 reply to this topic

#1 LiLaaron

LiLaaron
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 April 2006 - 03:51 AM

Hi There!

I am basically trying to get the value of the array only and make it a variable.

First my Code:

<?
$text = file_get_contents("../ez_sql.php"); 
preg_match_all('/define\s*\(([^,]+),([^\)]+)\)/i', $text, $matches); 
foreach($matches[1] as $key => $value) 
{ 
   $value = trim(trim($value), '\'"'); 
   $data[$value] = trim(trim($matches[2][$key]), '\'"'); 
} 
// show results: 
foreach($data as $key => $value)
{ 
  echo "<p>Key: $key, Value: $value !</p>\n"; 
} 
?>

This will show me 18 different defines ($keys) what i need is the first 5 values as variables so it may look like this:


$username = $value[1]; 
$password = $value[2]; 
$dbname = $value[3]; 
$server = $value[4]; 
$prefix = $value[5]; 

i would then do what i need to do with them, just i am finding it hard to make the value a variable.

Thanks
Aaron

#2 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 30 April 2006 - 04:27 AM

no need to call the foreach function if you're certain it's only the first 5 vars

$username = $data[0];
$password = $data[1];
$dbname = $data[2];
$server = $data[3];
$prefix = $data[4];





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users