Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Create an array from java code output in PHP

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
NGTLD
Asked:
NGTLD
1 Solution
 
Thomas4019Commented:
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
 
NGTLDAuthor Commented:
That would be great, but I cannot change the java.
0
 
CEHJCommented:
I'm confused. Is this a Java or php question? Returns to where and how?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
NGTLDAuthor Commented:
It is a PHP question.
0
 
objectsCommented:
can't you just use two for loops too loop through the array
0
 
NGTLDAuthor Commented:
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
 
objectsCommented:
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
 
NGTLDAuthor Commented:
Thanks, I saw that as well. It did not work, but the one a few post up did work.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now