简体   繁体   中英

Storing certain values from an array into a php variable

I'm creating a dynamic table of select database information in php where I'm pulling info from various oracle databases.

I executed a var_export on a select statement on one out of the 26 databases and displayed it results:

$dump2 = var_export($row2,true);
echo $dump2;

and I got the following:

array ( 'DB_NAME' => 'SOME_DATABASE', 'SYSTEM_DATE' => '25-JUL-13', 'TOTAL_DB_SIZE_GB'    => '50.50', 'DB_SIZE' => '48.60', 'TEMP_SIZE' => '3.30', 'REDO_SIZE' => '.61', 'ARC_SIZE' => '.21', )

What I want to do is export the result of DB_NAME, SYSTEM_DATE, TOTAL_DB_SIZE, etc.to a php variable. However, I don't want to export the result verbatim because I want to apply this export to other 25 databases later. Basically, I don't want to store the exact values such as "SOMEDATABASE" OR 25-JUL-13. Is there a way to store the value as a php variable where those variables can then be used for multiple oracle database connections?

I tried to do a substring approach where I took only a select number of characters from the var_export, but it wasn't a suitable solution:

v_db_name2=substr("$dump2",24,8). "\n";
$v_system_date=substr("$dump2",55,9). "\n";
$v_total_db_size=substr("$dump2",92,5). "\n";
$v_db_size=substr("$dump2",116,5). "\n";
$v_temp_size=substr("$dump2",142,4). "\n";
$v_redo_size=substr("$dump2",167,3). "\n";
$v_arc_size=substr("$dump2",190,3);

Do not know why you are using substr when you have the info already seprated out into an array

//Do whatever manipulation you need to do on $row2['DB_NAME'] etc
$dbName = str_replace("SOME_","",$row2['DB_NAME']);     
$systemDate = $row2['SYSTEM_DATE']; 

OR just keep the array itself and manipulate the values

$dbinfo = $row2;
$dbinfo['DB_NAME'] = str_replace("SOME_","",$dbinfo['DB_NAME'];
...//etc etc

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