Splite result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deshmukh999
Forum Commoner
Posts: 32
Joined: Mon Mar 15, 2010 2:01 am

Splite result

Post 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.
Last edited by Benjamin on Mon May 24, 2010 1:58 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Zyxist
Forum Contributor
Posts: 104
Joined: Sun Jan 14, 2007 10:44 am
Location: Cracow, Poland

Re: Splite result

Post 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;
}
deshmukh999
Forum Commoner
Posts: 32
Joined: Mon Mar 15, 2010 2:01 am

Re: Splite result

Post 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.
Last edited by Benjamin on Mon May 24, 2010 1:58 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Splite result

Post by AbraCadaver »

Cast it to an array:

Code: Select all

$aa = (array) MyClasss::checkLogin($post['f_nick'], $post['f_password']);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
deshmukh999
Forum Commoner
Posts: 32
Joined: Mon Mar 15, 2010 2:01 am

Re: Splite result

Post 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.
deshmukh999
Forum Commoner
Posts: 32
Joined: Mon Mar 15, 2010 2:01 am

Re: Splite result

Post 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.
Post Reply