For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, February 12, 2015

return array from php function

Problem:

How to return array as result from php function?

Solution:

Create a multiple or single key pair value array and return it from function and store in a variable.

Example:


<?php
    function my_arr_ret(){
    $result = array(
                'nm' => 'mynm',
                'id' => 'myid',
                'amount' => 12345.89,
                'code' => 'mycode'
            );
            return $result;
    }
    $my_arr=my_arr_ret();
    echo $my_arr['amount'];   
?>
Share:

0 comments:

Post a Comment

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights

Unable to resolve <website url> Try checking the for validity Google Pagespeed Insights   You have a website and want to test it'...

Ads Inside Post

Powered by Blogger.

Arsip