简体   繁体   English

将某些值从数组存储到php变量中

[英]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. 我在php中创建一个动态的选择数据库信息表,从各种Oracle数据库中提取信息。

I executed a var_export on a select statement on one out of the 26 databases and displayed it results: 我在26个数据库之一中的select语句上执行了var_export并显示了结果:

$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. 我想要做的是将DB_NAME,SYSTEM_DATE,TOTAL_DB_SIZE等的结果导出到一个php变量中。 However, I don't want to export the result verbatim because I want to apply this export to other 25 databases later. 但是,我不想逐字导出结果,因为我想稍后将此导出应用于其他25个数据库。 Basically, I don't want to store the exact values such as "SOMEDATABASE" OR 25-JUL-13. 基本上,我不想存储确切的值,例如“ SOMEDATABASE”或13-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? 有没有一种方法可以将值存储为php变量,然后可以将这些变量用于多个oracle数据库连接?

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: 我试图做一个子字符串方法,从var_export中只选择了一定数量的字符,但这不是一个合适的解决方案:

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 当您已经将信息分离到数组中时,不知道为什么要使用substr

//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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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