Solved

Create an array from java code output in PHP

Posted on 2009-07-08
8
282 Views
Last Modified: 2013-12-13
I have a java applet that returns a bunch of records in a string i.e.
$results[0][0]
$results[0][1]
$results[1][0]
$results[1][1]

I am lost, I can display this if I hard code echo $results[0][1] and so on, but how can I create an array that I could then do while loop with like I would with mysql. If there is a better way than that then please advise. I thought about looping through the first numeric value, but do not know how to check for the last number.
0
Comment
Question by:NGTLD
8 Comments
 
LVL 17

Expert Comment

by:Thomas4019
Comment Utility
I would have the java output a single String, each array element to be seperated by commas. Then with PHP use theexplode method. To split the String back into an array.
0
 

Author Comment

by:NGTLD
Comment Utility
That would be great, but I cannot change the java.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I'm confused. Is this a Java or php question? Returns to where and how?
0
 

Author Comment

by:NGTLD
Comment Utility
It is a PHP question.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 92

Expert Comment

by:objects
Comment Utility
can't you just use two for loops too loop through the array
0
 

Author Comment

by:NGTLD
Comment Utility
I am asking the wrong question. Sorry guys. I have a two dimensional array I need to implode. I am trying to figure that out now.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
found this, see if it helps:

<?php
                //  Can implode an array of any dimension
        //  Uses a few basic rules for implosion:
        //        1. Replace all instances of delimeters in strings by '/' followed by delimeter
        //        2. 2 Delimeters in between keys
        //        3. 3 Delimeters in between key and value
        //        4. 4 Delimeters in between key-value pairs
        function implodeMDA($array, $delimeter, $keyssofar = '') {
            $output = '';
            foreach($array as $key => $value) {
                if (!is_array($value)) {
                    $value = str_replace($delimeter, '/'.$delimeter, $value);
                    $key = str_replace($delimeter, '/'.$delimeter, $key);
                    if ($keyssofar != '') $key = $key.$delimeter.$delimeter;
                    $pair = $key.$keyssofar.$delimeter.$delimeter.$delimeter.$value;
                    if ($output != '') $output .= $delimeter.$delimeter.$delimeter.$delimeter;
                    $output .= $pair;
                }
                else {
                    if ($output != '') $output .= $delimeter.$delimeter.$delimeter.$delimeter;
                    if ($keyssofar != '') $key = $key.$delimeter.$delimeter;
                    $output .= $this->implodeMDA($value, $delimeter, $key.$keyssofar);
                }
            }
            return $output;
        }
0
 

Author Closing Comment

by:NGTLD
Comment Utility
Thanks, I saw that as well. It did not work, but the one a few post up did work.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now