MyBB Community Forums

Full Version: How to rename Array Keys?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2015-01-25, 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.
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);
?>
$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.
Pages: 1 2