SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prototype Array Method

    Hi all,

    I'm trying to iterate through an javascript array i have built up (as a result of using php_unserialize on a serialized php array string). I'm also using the Prototype.js script for other parts of the page, and this extends the array class so when i iterate i am encountering all the method names that Prototype provides. All i want are the values contained in the unserialized string - alert(ing) inside php_unserialize gives the correct values, outside not. I've also tried to use Prototype.each and other methods. Please help!!

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide some code explaining both side of the story?

    ie, code that displays the correct values and code that displays the incorrect values.

    Also, it would be useful to create a dummy array, use php_serialize and past it with your code so we look at the code correctly.

    I've been looking into it and the array that is created should look like this

    Code:
     var someArray = new Array();
     someArray['Name'] = 'Value';
    so both the array item container and the content are values.

    the web site has an example with is like

    Code:
     for(i in someArray)
     {
        document.write(i + ' - ' + someArray[i] + '<br />');
     }
    which would output

    Code:
     Name - Value<br />
    Have you tried using your array like that?


  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've a bunch of php which outputs functions like this, which includes a call to the php_unserialize script: http://www.phpguru.org/downloads/PHP_Unserialize/:

    <script type="text/javascript">function updateaddFeedaddXsltSwitch(propogatorId){
    unserializegroupaddFeedaddXsltSwitch = 'a:1:{s:7:"addFeed";a:1:{i:0;s:12:"propogatorId";}}';var groupaddFeedaddXsltSwitch = PHP_Unserialize(unserializegroupaddFeedaddXsltSwitch);
    refreshFromArray(groupaddFeedaddXsltSwitch);
    }</script>

    Invoking this calls the refreshFromArray function, in which i'm currently just debugging and getting the problem described above:

    function refreshFromArray(jsArray){
    for(i in jsArray) alert(i);
    }

    As mentioned, i have the prototype.js declared as an import so the actual Javascript Array() class has all the extra methods that prototype provides. All i'd like to do is strip out these additional things and just return the array that i feed into php_unserialize. Prototype.js, btw, is at http://prototype.conio.net/

    Any help would be great...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •