How to make a things in a string be a part of a array

I am making a thing that involves users. All the users are stored in an array, and I want the program to read the contents of a file, which stores the stuff that is to be put into the array, like:

I am making a thing that involves users. All the users are stored in an array, and I want the program to read the contents of a file, which stores the stuff that is to be put into the array, like:

"user1" => "pwd", "user2 => "pwd"

in the file. Then, I use file_get_contents to get all the data into a string called $a. I put $a into the array like:

array($a);

And I want the stuff in $a to be a part of the array, not something in a array in total. How do I do that? Please help. Thanks.

My code is:

fopen("authkey.txt", "r");
$a = file_get_contents("authkey.txt");
$auth_users = array('admin' => 'something', $a);
// I want the things in $a to be a part of the array, not a string


How to convert an Array to String in Java?

How to convert an Array to String in Java?

In this post, you'll learn the various methods to convert an Array to String in Java

Below are the various methods to convert an Array to String in Java:

1. Arrays.toString() method:

Arrays.toString() method is used to return a string representation of the contents of the specified array. The string representation consists of a list of the array’s elements, enclosed in square brackets (“[]”). Adjacent elements are separated by the characters “, ” (a comma followed by a space). It returns “null” if the array is null.

// Java program to demonstrate 
// working of Arrays.toString() 

import java.io.*; 
import java.util.*; 

class GFG { 
	public static void main(String[] args) 
	{ 

		// Let us create different types of arrays and 
		// print their contents using Arrays.toString() 
		boolean[] boolArr 
			= new boolean[] { true, true, false, true }; 
		char[] charArr 
			= new char[] { 'g', 'e', 'e', 'k', 's' }; 
		double[] dblArr 
			= new double[] { 1, 2, 3, 4 }; 
		int[] intArr 
			= new int[] { 1, 2, 3, 4 }; 
		Object[] objArr 
			= new Object[] { 1, 2, 3, 4 }; 

		System.out.println( 
			"Boolean Array: "
			+ Arrays.toString(boolArr)); 
		System.out.println( 
			"Character Array: "
			+ Arrays.toString(charArr)); 
		System.out.println( 
			"Double Array: "
			+ Arrays.toString(dblArr)); 
		System.out.println( 
			"Integer Array: "
			+ Arrays.toString(intArr)); 
		System.out.println( 
			"Object Array: "
			+ Arrays.toString(objArr)); 
	} 
} 

Output

Boolean Array: [true, true, false, true]
Character Array: [g, e, e, k, s]
Double Array: [1.0, 2.0, 3.0, 4.0]
Integer Array: [1, 2, 3, 4]
Object Array: [1, 2, 3, 4]
2. StringBuilder append(char[]):

The java.lang.StringBuilder.append(char[]) is the inbuilt method which appends the string representation of the char array argument to this StringBuilder sequence.

// Java program to illustrate the 
// StringBuilder.append(char[]) method 

import java.lang.*; 

public class Geeks { 

	public static void main(String[] args) 
	{ 

		StringBuilder sbf 
			= new StringBuilder("We are geeks "); 
		System.out.println(sbf); 

		// Char array 
		char[] astr 
			= new char[] { 'G', 'E', 'E', 'k', 'S' }; 

		// Appends string representation of char 
		// array to this String Builder 
		sbf.append(astr); 
		System.out.println("Result after"
						+ " appending = "
						+ sbf); 

		sbf = new StringBuilder("We are -"); 
		System.out.println(sbf); 

		// Char array 
		astr = new char[] { 'a', 'b', 'c', 'd' }; 

		/* Appends string representation of char 
				array to this StringBuilder */
		sbf.append(astr); 
		System.out.println("Result after appending = " + sbf); 
	} 
} 

Output:

We are geeks 
Result after appending = We are geeks GEEkS
We are -
Result after appending = We are -abcd

PHP Array Unique Sort Regular not working as expected

I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work.

I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work.

I'm trying to filter out the redundant data.

Notice that [Order] and its key value pairs are all the same. But [Transaction] and its key value pairs are unique.

I need to get the [Order] element data and combine it with the 3 different [Transaction] elements.

My array

Array
(
    [0] => Array
        (
            [Order] => Array
                (
                    [PO] => TR11214
                    [OrderID] => 242856952012
                )
        [Transaction] => Array
            (
                [TransPO] => TR11211
                [TransactionPrice] => 91.17
            )

    )

[1] => Array
    (
        [Order] => Array
            (
                [PO] => TR11214
                [OrderID] => 242856952012
            )

        [Transaction] => Array
            (
                [TransPO] => TR11212
                [TransactionPrice] => 180.41
            )

    )

[2] => Array
    (
        [Order] => Array
            (
                [PO] => TR11214
                [OrderID] => 242856952012
            )

        [Transaction] => Array
            (
                [TransPO] => TR11213
                [TransactionPrice] => 209.99
            )

    )

)

The final array I need will look something like this.

Array
(
[Order] => Array
(
[PO] => TR11214
[OrderID] => 242856952012
)

[Transaction] => Array
    (
        [0] => Array
            (
                [TransPO] => TR11211
                [TransactionPrice] => 91.17
            )

        [1] => Array
            (
                [TransPO] => TR11212
                [TransactionPrice] => 180.41
            )

        [2] => Array
            (
                [TransPO] => TR11213
                [TransactionPrice] => 209.99
            )

    )

)

I can flatten the original array and then use array_unique, but wanted to see if there is a better way to accomplish what I need.

my code:

$myarray = array(
0 => array(
"Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
"Transaction" => array("TransPO" => "TR11211", "TransactionPrice" => 91.17)
),
1 => array(
"Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
"Transaction" => array("TransPO" => "TR11212", "TransactionPrice" => 180.41)
),
2 => array(
"Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
"Transaction" => array("TransPO" => "TR11213", "TransactionPrice" => 209.99)
)
);

print_r(array_unique($myarray, SORT_REGULAR));


Read a string char by char from an associative pointer array

I hope the title of my question is correct.

I hope the title of my question is correct.

I have a stringpool

char **string_pool;

that gets initiated in a function like

string_pool = malloc( sizeof(char *) * 1024);

i get strings from stdin and scanf them into the array

scanf("%[^\n]s", &string_pool[index]);

so i can print it out using printf

printf("gets %s\n", &string_pool[index]);

how can i

  • get the length of string_pool[index]
  • read string_pool[index] char by char in a loop

Thank you

Edit

Maybe i should explain it a bit more, its a virtual machine with a virtual instruction set and a program like

push 1
read
gets

should :

  • push 1 on the stack -> let x be 1
  • read stdin as string into string_pool[x]
  • push all characters onto the stack

the functions looks like

    case GETS: {
        int index = popv(); // index is already on top of the stack
        int strl = strlen(&string_pool[index]);
    printf("gets %s with a length of %d\n", &string_pool[index], strl);
    // pseudo code
    // push each char as integer on the stack
    foreach(char in string_pool[index]) push((int)char);

    break;
}

case READ: {  
    int index = popv();          
    scanf("%[^\n]s", &string_pool[index]);
    break;
}

case WRITE: {  
    int index = popv();          
    printf("%s", &string_pool[index]);
    break;
}

My problem is in the GETS case. I want to push every char as int onto the stack.