Jump to content

PHP Array values


maliary

Recommended Posts

I am working a database retrival code and I can only obtain partial data from a string.

$rows['serial_value'] is a string made of a combination of two distinct values separeted by = and & symbols.

 

How would I obtain the two values and out put them separetly?

 

This is the query:

  $depts = $db->Execute("SELECT $dbtable.serial_value,$dbtable.type,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit  FROM $dbtable,$table WHERE ($table.group_id = $dbtable.group_id) AND $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"); 

   while($rows= $depts->FetchRow()){
   
     $h = $rows['serial_value']; // This is a string
     $keywords = preg_split ("/[\=,\&]+/", "$h"); // Remove the = and & symbols in the string
     
}

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/
Share on other sites

 

 

Thanks guys,

 

But its not the split thats the problem, its after i split.

 

for instance this is the string - &=119=-&=128=2&=129=3&=130=-&=132=-&=141=-&=152=-&=153=-&=154=-&=155=-&=186=-&=195=-&=198=-&=223=-&=226=2&=119=-&=128=-&=129=-&=130=-&=132=-&=141=-&=152

 

I want to display it like

 

119    -    -

128    -    2

129    -    3

 

that way.

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305226
Share on other sites

try

<?php
$string = '&=119=-&=128=2&=129=3&=130=-&=132=-&=141=-&=152=-&=153=-&=154=-&=155=-&=186=-&=195=-&=198=-&=223=-&=226=2&=119=-&=128=-&=129=-&=130=-&=132=-&=141=-&=152';
echo $string = str_replace('=', ' - ', str_replace('&=', "<br />\n", trim($string, '&=')));
?>

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305231
Share on other sites

i try with your string and output look

X-Powered-By: PHP/4.4.4
Content-type: text/html

119 - -<br />
128 - 2<br />
129 - 3<br />
130 - -<br />
132 - -<br />
141 - -<br />
152 - -<br />
153 - -<br />
154 - -<br />
155 - -<br />
186 - -<br />
195 - -<br />
198 - -<br />
223 - -<br />
226 - 2<br />
119 - -<br />
128 - -<br />
129 - -<br />
130 - -<br />
132 - -<br />
141 - -<br />
152

if you want just output this, string is OK

if you want some calculation with data array is better

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305259
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.