how to get specific values which is starting with 3

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

pavithrar
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Jun 12, 2013 4:58 am

how to get specific values which is starting with 3

Postby pavithrar » Mon Jun 17, 2013 11:45 pm

the following code is

Code: Select all

$getaccountlistdetails = new SoapClient("AccountService.wsdl");
$GetAccountListResponse = $getaccountlistdetails->get_account_list(array("limit" => 10, "offset" => 0, "i_customer" => 20754, "i_batch" => 11232));
$account_list = $GetAccountListResponse->{'account_list'};
foreach ($account_list as $value) {
   $account_number = $value->account_id;
   echo "$account_id" . "<br>";
}

the above code out put is:
32695
45653
32785
89894
how to get the values which is starting with 3
i need to display like
32695
32785

pbs
New php-forum User
New php-forum User
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India
Contact:

Re: how to get specific values which is starting with 3

Postby pbs » Tue Jun 18, 2013 2:51 am

use substr PHP function like this in your for loop

Code: Select all

foreach ($account_list as $value) {
   $account_number = $value->account_id;
   if (substr($account_number,0,1) == 3)
        echo "$account_id" . "<br>";
}

pavithrar
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Jun 12, 2013 4:58 am

Re: how to get specific values which is starting with 3

Postby pavithrar » Tue Jun 18, 2013 3:46 am

pbs wrote:use substr PHP function like this in your for loop

Code: Select all

foreach ($account_list as $value) {
   $account_number = $value->account_id;
   if (substr($account_number,0,1) == 3)
        echo "$account_id" . "<br>";
}


it is working. thank u so much for fast reply

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how to get specific values which is starting with 3

Postby johnj » Thu Jun 20, 2013 9:48 pm

you can also use strpos() to do this.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron