Setting javascript variable to PHP array's specific index -


i have 1 (very) big php array (with 649 indexes). want set javascript variable specific index of , index depend on variable. there way? know can copy whole php array javascript array using json_encode($phparray) , don't want whole array loaded on client side (for speed , sort of security).

 $phparray[0] = "i first element";  $phparray[1] = "i second element";  /* ......... */  $phparray[100] = "i 100th element"; 

and now, let say, want second element of $phparray ? how can it?

here example using jquery $.post method:

$(document).ready(function(){   var my_var;   $.post("my-php-page.php",          {my_index: 1},          function(data) {            my_var = data.my_value;          },          "json"); }); 

my-php-page.php

<?php  $phparray[0] = "i first element";  $phparray[1] = "i second element";  /* ......... */  $phparray[100] = "i 100th element";  echo json_encode(array("my_value" => $phparray[$_post['my_index']])); ?> 

is want?


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -