i am getting array output as:
Array ( [0] => Array ( [0] => 000000 [1] => 000400 [2] => 000450 ) ) Array (this should be 1 [0] => Array ( [0] => 000350 [1] => 000400 ) )
i want output like this:
Array ( [0] => Array ( [0] => 000000 [1] => 000400 [2] => 000450 ) ) Array ( [1] => Array ( [0] => 000350 [1] => 000400 )
my php code is:
$sql = "
SELECT
ac_no, cust_name,
GROUP_CONCAT(install_amt SEPARATOR ',') as installamt
FROM ankali_slabpay
WHERE agent_id=$agent_id
GROUP BY ac_no";
$select = mysql_query($sql);
if (!$select) {
trigger_error("SQL Query failed: " . mysql_error(), E_USER_ERROR);
}
while($row1 = mysql_fetch_array($select)) {
$arr = array();
$arr[] = explode(",", $row1['installamt']);
print_r($arr);
}
take print_r($arr); out of while loop
if i put out of while loop, it’s just printing one array i.e. Array ( [0] => Array ( [0] => 000350 [1] => 000400 ) )
you have initialized $arr = array(); in while loop, it should also be above while loop
your while loop should be
$arr = array();
while($row1 = mysql_fetch_array($select))
{
$arr[] = explode(",", $row1['installamt']);
}
print_r($arr);
thanks now it’s working outside while loop, but the main issue is still there
current output:
Array ( [0] => Array ( [0] => 000000 ) [1] => Array ( [0] => 000400 ) [2] => Array ( [0] => 000450 ) [3] => Array ( [0] => 000350 ) [4] => Array ( [0] => 000400 ) )
i am expecting below output
Array (
[0] => Array (
[0] => 000000
[1] => 000400
[2] => 000450
),
[1] => Array (
[0] => 000350
[1] => 000400
)
)
it think it should work, bcoz explode will return you single dimensional array and we are assigning this to new array variable
try using variable for exploded array like this
$arr = array();
while($row1 = mysql_fetch_array($select))
{
$arr1 = array();
$arr1 = explode(",", $row1['installamt']);
$arr[] = $arr1;
}
print_r($arr);
thanks pbsonawane , one more issue
$b = array(000350,000400,000450);
$a = Array ( [0] => Array ( [0] => 000000 [1] => 000400 [2] => 000450 ) [1] => Array ( [0] => 000350 [1] => 000400 ) )
match the values of $b with $a if match found replace the matching value in $b with 000000
for example:
$i=0;
foreach($b as $k=>$v)
{
if($v==$a[$i])
{
$b[$k]='000000';
}
$i++;
}