arrays

How to return array of C++ objects from a PHP extension

I need to have my PHP extension return an array of objects, but I can't seem to figure out how to do this. I have a Graph object written in C++. Graph.getNodes() returns a std::map<int, Node*>. Here's the code I have currently: struct node_object { zend_object std; Node *node; }; zend_class_entry *node_ce; then PH...

Array indexOf implementation for Internet Explorer

There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being probl...

How can I extract just the elements I want from a Perl array?

Hey I'm wondering how I can get this code to work. Basically I want to keep the lines of $filename as long as they contain the $user in the path: open STDERR, ">/dev/null"; $filename=`find -H /home | grep $file`; @filenames = split(/\n/, $filename); for $i (@filenames) { if ($i =~ m/$user/) { ...

Why do all of these methods of accessing an array work?

It seems to me that some of these should fail, but they all output what they are supposed to: $, = "\n"; %test = ( "one" => ["one_0", "one_1"], "two" => ["two_0", "two_1"] ); print @{$test{"one"}}[0], @{$test{"one"}}->[0], $test{"two"}->[0], $test{"one"}[1]; Why is this? ...

Array construction and negative numbers

I was implementing a routing algorithm in javascript, but when I assign a negative one variable in the array gives me this error: invalid array length. var node = new Array() node[0] = new Array(6,7) node[1] = new Array(5,-4,8) node[2] = new Array(-2) //Here, invalid array length I do not know how to resolve this error. ...

Representing a number in a byte array (java programming)

I'm trying to represent the port number 9876 (or 0x2694 in hex) in a two byte array: class foo { public static void main (String args[]) { byte[] sendData = new byte[1]; sendData[0] = 0x26; sendData[1] = 0x94; } } But I get a warning about possible loss of precision: foo.java:5: possible loss of precision found ...

Filling array with numbers

Hello, I have such situation: There is 8 div-blocks with ids like 'rateN_wrapper' where is 'N' is the number of div: <div id="rate1_wrapper"> <a href="#" id="0_1">...</a> <a href="#" id="0_2">...</a> <a href="#" id="0_3">...</a> </div> <div id="rate2_wrapper"> <a href="#" id="1_1">...</a> <a href="#" id="1_2">...</a> <a hre...

Is there a PHP function to combine the results of 2 arrays based off of keys?

Hey Everyone, If I have the following arrays arry1 = array( 101 => array( 'title1' => 'data', 'title2' => 'data', 'title3' => 'data' ), 102 => array( 'title1' => 'data', 'title2' => 'data', 'title3' => 'data' ), . . . ); arry2 = array( 101 => array( ...

Why getting active record error when trying to work on arrays?

I have the following association in my User model: has_and_belongs_to_many :friends, :class_name => 'User', :foreign_key => 'friend_id' I have the following uniqueness constraint in my user_users table: UNIQUE KEY `no_duplicate_friends` (`user_id`,`friend_id`) In my code, I am retrieving a user's friends --> friends = user.friends....

Sorting an array of structs

I have an array of structs called leaders. The struct class looks like this, for contextual info: class Leader < Struct.new(:rank, :user); end Two questions: How do I sort the array of structs by rank? How do I sort the array of structs by rank and by user.created_at? ...

How can I get a value out of a jQuery object?

I am returning some data (example below) and saving it to a jQuery object (or is this an array and I am confusing the two?) when I log the variable that is the object it has the values I am looking for but how do I access the data inside this object? code $itemPosition = { 'top': $item.offset().top, 'left':$item.offset().left }...

How Can I Set Up a "Where" Statement with a PHP Array

Am I able to apply "where" statements to PHP arrays, similar to how I would be able to apply a "where" statement to a MySQL query? For example, suppose I have the following array: $recordset = array( array('host' => 1, 'country' => 'fr', 'year' => 2010, 'month' => 1, 'clicks' => 123, 'users' => 4), array('host' => 1, 'country' => '...

ColdFusion, HowTo Convert a String to an Array?

Given the following string in ColdFusion: ul[0][id]=main1 &ul[0][children][0][id]=child2 &ul[0][children][0][class]= &ul[1][id]=main3 &ul[2][id]=main4 &ul[3][id]=main5 How can I create an array with the info above? Thanks ...

Java constructor and modify the object properties at runtime

Note: This is an assignment Hi, I have the following class/constructor. import java.io.*; class Set { public int numberOfElements = 0; public String[] setElements = new String[5]; public int maxNumberOfElements = 5; // constructor for our Set class public Set(int numberOfE, int setE, int maxN...

J2me - Arrays vs vector ?

if we have to implementations of string split for j2me, one returns vector and the other returns array , in terms of performance on hand held devices which one is the best choice ? ...

Do I have to start from beginning?

If I have: std::size_t bagCapacity_ = 10; std::size_t bagSize = 0; A** bag = new A*[bagCapacity_]; while (capacity--) { bag[capacity] = new A(bagSize++); //**here I'm loading this array from the end is it ok?** } And also can I delete those object from starting at the end of the array? while (capacity--) { delete bag[capacity]; ...

Typecast a ArrayList.toArray() in Java to normal array

I'm having some trouble to do the following: int[] tmpIntList = (int[])MyArrayList.toArray(someValue); MyArrayList contains only numbers. I get a typecast error since ArrayList only returns Object[] but why isnt it possible to turn it into a int[] ? ...

php: array_replace_recursive alternative

I need a solution for array_replace_recursive, because my php-version isn't high enough. I want to use this code: $_GET = array_replace_recursive($_GET, array("__amp__"=>"&")); easy, isn't it? ...

php access array value from function return

silly php question... why cant i do this? echo Auth::getFullUser()[ 'country' ]; instead you have to do this $user = Auth::getFullUser(); echo $user[ 'country' ]; ...

second sorting with php usort

So Ive got a pretty big array of data and need to sort them by two criteria. There is variable $data['important'] and $data['basic']. They are simple numbers and I am using uasort to sort $data firstly by important and then by basic. So Important | Basic 10 | 8 9 | 9 9 | 7 7 | 9 The usort function i...