How to rename Array Keys?
#11
(01-25-2015, 11:36 AM)Ad Bakker Wrote: This is the outcome of the loop, that is it, doesn't it?


new array
Array ( [0] => uploads/testing1.txt [1] => uploads/random.txt [2] => uploads/mytest.docx [3] => uploads/testing2.php [4] => uploads/atest.txt ) 

Yes, that's correct.
Reply
#12
Another solution, which transforms the two dimensional array to a one dimensional with the same name(the actual work is done in line 10):
<?php 
$array = array(
    array("filename","uploads/testing1.txt"), 
    array("filename","uploads/random.txt"), 
    array("filename","uploads/mytest.docx"),
    array("filename","uploads/testing2.php"),
    array("filename","uploads/atest.txt"),);
echo "old contents of array <br />";
print_r($array);
foreach ($array as &$temp) $temp = $temp[1];
echo "<br /><br />new contents of array<br />";
print_r($array);
?>
Regards, Ad Bakker (NL)
Reply
#13
$query = $db->simple_select('table', 'column', 'where clause');
while ($result = $db->fetch_field($query, 'column')) {
    $results[] = $result;
}

print_r($results);

This is the simplest and neatest method I could think. You don't need to manipulate arrays if you can make them look the way you want them to be as the query runs.
[Image: fSGNVQj.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)