Solved

Create an array from java code output in PHP

Posted on 2009-07-08
8
284 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
ID: 24808830
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
ID: 24808850
That would be great, but I cannot change the java.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24808871
I'm confused. Is this a Java or php question? Returns to where and how?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:NGTLD
ID: 24809052
It is a PHP question.
0
 
LVL 92

Expert Comment

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

Author Comment

by:NGTLD
ID: 24809607
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
ID: 24809662
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
ID: 31601342
Thanks, I saw that as well. It did not work, but the one a few post up did work.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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