Re: [PHP] Troubles from the newb again

2007-03-10 Thread M.Sokolewicz

Jeff Taylor wrote:

Yeah I have, but what I dont understand is that the value of $name is an
object, and was accepted in the original array as the index:

the original array was:

$me = new Toon(,xxx,xxx,,xxx,etc,etc,etc)
$him = new Toon(xxx,xx,x,etc,etc,etc,etc)


$array=array($me,$him)


Hell no,
there's a difference between:
$array[$me] and array($me);
The first results in:
$array[$me] = null;
the other results in
$array[0] = $me;
Note that in the 2nd one you assign $me as the first value of the array, 
and in the 1st one you assign $me to be the first index/key of the array 
 (with a null value).




So this new array, I want to isolate those toons still alive:

if alive then
add toon to new array

Is this possible in anyway?


The reason why I dont want it to put it in a value:

   foreach ($newarray as $name)
   {
if (in_array($name,$characters))
{
 $newarray[$name] = 1;
}
else
{
 $newarray[$name] = 2;
}
   }


Sorry for the spam everyone
Then use $name as being an actual NAME (aka "string") instead of the 
entire `toon` you are talking about (aka "object").


- tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Troubles from the newb again

2007-03-09 Thread Robert Cummings
On Sat, 2007-03-10 at 16:39 +1100, Ryan Fielding wrote:
> Robert Cummings wrote:
> > On Sat, 2007-03-10 at 15:31 +1030, Jeff Taylor wrote:
> >   
> >> Hey everyone,
> >> Newb back again - Im trying to populate my arrays, but getting this error
> >> again:
> >> Warning: Illegal offset type in
> >> 
> >
> > This usually means that you are using a non-scalar value as an index.
> > Use var_dump( $array ) to see what's in there. You will probably find
> > one of the following: an array, and object, or the null value.
> >
> > Cheers,
> > Rob.
> >   
> A good habit to get into is always using if(is_array()) when using foreach.

Sure, if you don't know what is in the array and are quite happy to
waste cycles calling a function on every single value :( ... In other
words... HELL NO! You shouldn't have to filter your data if it should
already be in an expected format. If it isn't in the expected format
then you have a bug -- fix the bug instead of "handling" it within every
foreach loop that touches the data.

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



Re: [PHP] Troubles from the newb again

2007-03-09 Thread Jeff Taylor
Yeah I have, but what I dont understand is that the value of $name is an
object, and was accepted in the original array as the index:

the original array was:

$me = new Toon(,xxx,xxx,,xxx,etc,etc,etc)
$him = new Toon(xxx,xx,x,etc,etc,etc,etc)


$array=array($me,$him)


So this new array, I want to isolate those toons still alive:

if alive then
add toon to new array

Is this possible in anyway?


The reason why I dont want it to put it in a value:

   foreach ($newarray as $name)
   {
if (in_array($name,$characters))
{
 $newarray[$name] = 1;
}
else
{
 $newarray[$name] = 2;
}
   }


Sorry for the spam everyone

"Robert Cummings" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sat, 2007-03-10 at 15:31 +1030, Jeff Taylor wrote:
> > Hey everyone,
> > Newb back again - Im trying to populate my arrays, but getting this
error
> > again:
> > Warning: Illegal offset type in
>
> This usually means that you are using a non-scalar value as an index.
> Use var_dump( $array ) to see what's in there. You will probably find
> one of the following: an array, and object, or the null value.
>
> 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



Re: [PHP] Troubles from the newb again

2007-03-09 Thread Ryan Fielding

Robert Cummings wrote:

On Sat, 2007-03-10 at 15:31 +1030, Jeff Taylor wrote:
  

Hey everyone,
Newb back again - Im trying to populate my arrays, but getting this error
again:
Warning: Illegal offset type in



This usually means that you are using a non-scalar value as an index.
Use var_dump( $array ) to see what's in there. You will probably find
one of the following: an array, and object, or the null value.

Cheers,
Rob.
  

A good habit to get into is always using if(is_array()) when using foreach.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Troubles from the newb again

2007-03-09 Thread Robert Cummings
On Sat, 2007-03-10 at 15:31 +1030, Jeff Taylor wrote:
> Hey everyone,
> Newb back again - Im trying to populate my arrays, but getting this error
> again:
> Warning: Illegal offset type in

This usually means that you are using a non-scalar value as an index.
Use var_dump( $array ) to see what's in there. You will probably find
one of the following: an array, and object, or the null value.

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