Page 1 of 1

Splite result

Posted: Sun May 23, 2010 11:40 pm
by deshmukh999
Hi Gyes,

I called one function that returns a object.
here checkLogin is a ststic function of MyCAlss.

Code: Select all

$aa=MyClasss  :: checkLogin($post['f_nick'],$post['f_password']);
 print_r($aa);
it returns a following result
[text]StatusResult Object ( [status:private] => [descriptions:private] => Array ( [0] => Login is not successful. ) [data:private] => )[/text]

above result I want in a variable so that I could process some checks.
How to get this result as a simple array.
Please help me to get it solve.

Re: Splite result

Posted: Mon May 24, 2010 12:49 am
by Zyxist
The method returned you an object. I suppose the author gave it some interface that allows you to work with it. Basically, he might also present some interface to convert it to array, but this is not obligatory. Without this interface, you cannot convert an object in general, however in some cases it is possible. For example, if the object implements Interator interface, you could do:

Code: Select all

$array = array();
foreach($object as $key => $value)
{
   $array[$key] = $value;
}

Re: Splite result

Posted: Mon May 24, 2010 1:54 am
by deshmukh999
Thanks for ur reply.
It is not giving solution.
I did as below

Code: Select all

$aa=MyClass :: checkLogin(trim($post['f_nick']),trim($post['f_password']));
 
		   $array =  array();
			foreach($aa as $key => $value)
			{
			  $array[$key] = $value;
			}

                print_r( $aa);

			echo '<br>';

		 print_r($array);
and got result as
[text]StatusResult Object ( [status:private] => [descriptions:private] => Array ( [0] => Login is not successful. ) [data:private] => )
Array ( ) [/text]

In answer it returns blank array.
Please help me to solve it.

Re: Splite result

Posted: Mon May 24, 2010 10:16 am
by AbraCadaver
Cast it to an array:

Code: Select all

$aa = (array) MyClasss::checkLogin($post['f_nick'], $post['f_password']);

Re: Splite result

Posted: Tue May 25, 2010 1:30 am
by deshmukh999
Daer Guyes,

After when I used print_r function
I got the following answer

Array ( [�StatusResult�status] => [�StatusResult�descriptions] => Array ( [0] => Login is not successful. ) [�StatusResult�data] => )

Here the problem is how can I splite and take these values in differen variables.

As well with the answer ? mark sign is coming. I am not getting how to remove and what exact is the index name here.

Re: Splite result

Posted: Thu May 27, 2010 12:16 am
by deshmukh999
After when I used print_r function
I got the following answer

Array ( [�StatusResult�status] => [�StatusResult�descriptions] => Array ( [0] => Login is not successful. ) [�StatusResult�data] => )

Can anyone tell me why this question mark "?" is coming in the result.

How can I get the exact answer.