[OpenSIPS-Users] For-Each Example

Kneeoh kneeoh at yahoo.com
Mon Sep 14 16:18:26 CEST 2015


Thanks Bogdan, that did the trick.
 


     On Wednesday, September 9, 2015 6:14 AM, Bogdan-Andrei Iancu <bogdan at opensips.org> wrote:
   

  Hi,
 
 If you have an AVP holding multiple value (instances), you can iterate through all of them as:
 
 $var(n) = 0;
 while ( $(avp(my_avp)[$var(n)]) != NULL ) {
     xlog("value of my avp on position $var(n) is $(avp(my_avp)[$var(n)]) \n");
     $var(n) = $var(n) + 1 ;
 }
 
 Regards,
  Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com On 09.09.2015 00:01, Kneeoh wrote:
  
  I'm trying to figure out how to iterate through an indexed $avp that holds json query results. The docs are kind of spotty. Can someone share a working snippet of code that iterates through an $avp ? This one isn't quite working for me. First off it says only $var and $avp can be iterated, but this example has a $json var.
  
  # iterate through all JSON documents returned by a MongoDB query
    cache_raw_query("mongodb:location", "{... find ...}", "$avp(res)");
    for ($json(contact) in $(avp(res)[*]))
        xlog("Found: $json(contact/phone) $json(contact/email)\n");
 
   
  
 _______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
 
 
 

  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20150914/a46b64d3/attachment.htm>


More information about the Users mailing list