On Wed, 2006-05-03 at 13:27, Jason Gerfen wrote:
> I am looking for some information on how to do this the correct way,
> here is the data I am working with:
>
> Array
> (
> [hostname-0] => hostname
> [mac-0] => 00:0a:b3:aa:00:5d
> [ip-0] => 192.168.0.1
> [subnet] => MMC-Subnet
> [group] => MMC-PXE
> [hostname-1] => tester01
> [mac-1] => 00:09:02:bb:cc:zz
> [ip-1] => 192.168.0.2
> [hostname-2] => new-test
> [mac-2] => 00:09:02:bb:cc:99
> [ip-2] => 192.168.0.3
> [cmd] => edit
> [import] => Re-submit
> )
>
> Here is how I need the above data to look when finished processing.
>
> Array
> (
> [0] => Array
> (
> [0] => hostname
> [1] => 00:0a:b3:aa:00:5d
> [2] => 192.168.0.1
> )
>
> [1] => Array
> (
> [0] => tester01
> [1] => 00:09:02:bb:cc:zz
> [2] => 192.168.0.2
> )
>
> [2] => Array
> (
> [0] => new-test
> [1] => 00:09:02:bb:cc:99
> [2] => 192.168.0.3
> )
>
> )
>
> here is the code I am using.
>
> <?PHP
> function ReFilter( $new ) {
> $x = 0;
> foreach( $new as $key => $value ) {
> if( eregi( 'hostname', $key ) ) {
> echo "HOSTNAME: " . $key . " => " . $value . "<br>";
> $arr[$x] = $value;
> }
> if( eregi( 'mac', $key ) ) {
> echo "MAC: " . $key . " => " . $value . "<br>";
> $arr[$x] = $value;
> }
> if( eregi( 'ip', $key ) ) {
> echo "IP: " . $key . " => " . $value . "<br>";
> $arr[$x] = $value;
> }
> if( eregi( 'subnet', $key ) ) {
> echo "SUBNET: " . $key . " => " . $value . "<br>";
> $arr[$x] = $value;
> }
> if( eregi( 'group', $key ) ) {
> echo "GROUP: " . $key . " => " . $value . "<br>";
> $arr[$x] = $value;
> }
> $x++;
> }
> $data = $arr;
> return $data;
> }
> ?>
>
> I realize I am missing a loop, but am unsure of the best practice on it.
> Thanks in advance
<?php
$i = 0;
$cleanArray = array();
while( isset( $yourArray['hostname'."-$i"] ) )
{
$cleanArray[] = array
(
$yourArray['hostname'."-$i"],
$yourArray['mac'."-$i"],
$yourArray['ip'."-$i"],
);
}
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php