[Solved] Security of PHP POST Array

An attacker cannot “escape” a PHP array, because the contents of the array are not executed as code. It may contain a string of PHP, but that string is not executed. What may be insecure is how your PHP code handles the user input later on. If you are outputting the data without sanitising it, … Read more

[Solved] create multidimetional array associative array

Should really be trying this yourself mate, but this should help: $arr = array( 1=>’xyz’, 2=>’abc’, 3=>’pqr’ ); $MultiArr = array(); $i = 0; foreach($arr as $ID=>$Name){ $MultiArr[$i][‘id’] = $ID; $MultiArr[$i][‘name’] = $Name; $i++; } print_r($MultiArr); 3 solved create multidimetional array associative array

[Solved] PHP nested array into HTML list

What you are looking for is called Recursion. Below is a recursive function that calls itself if the value of the array key is also an array. function printArrayList($array) { echo “<ul>”; foreach($array as $k => $v) { if (is_array($v)) { echo “<li>” . $k . “</li>”; printArrayList($v); continue; } echo “<li>” . $v . … Read more

[Solved] java.lang.ArrayIndexOutOfBoundsException when adding new elements to an array? [closed]

This works for me. public class PersonService { protected int lastItemInPersonArray = 0; private Person[] persons = new Person[100]; public void addPersonToPersonArray(Person personToAdd) { persons[lastItemInPersonArray++] = personToAdd; } public static void main(String[] args) { PersonService ps = new PersonService(); ps.addPersonToPersonArray(new Person(“P 1”)); ps.addPersonToPersonArray(new Person(“P 2”)); ps.addPersonToPersonArray(new Person(“P 3”)); System.out.println(ps.persons[0].nome); System.out.println(ps.persons[1].nome); System.out.println(ps.persons[2].nome); } } class Person{ … Read more

[Solved] Count an array php

While this question is poorly worded, I think I understand what you are asking for. Here’s what you should do. I am not all that fluent in php so please make sure that you look over the code snippets that I write instead of copy/pasting them. Find the maximum X and Y values. Instantiate and … Read more

[Solved] Converting an array object to another object-Part 2 in javascript

function yymmddToString(yymmdd) { var months = [‘January’, ‘February’, ‘March’, ‘April’ …..]; var x = yymmdd.split(‘-‘); return months[parseInt(x[1], 10)] + ‘ ‘ + x[0]; } var result = data1.reduce(function(result, datum) { var x = result[datum.name] = result[datum.name] || {}; x[yymmddToString(datum.time)] = datum.value; return result; }, {}); 6 solved Converting an array object to another object-Part 2 … Read more

[Solved] Write longest and shortest palindrome from text file

Similar to previous answer but with the following suggestions Initialize longest and shortest. Ignore case when comparing. Could still do this with SequenceEqual instead of comparing strings. May not be needed if you know you won’t be comparing Anna to annA. When checking if you found the shortest you need to remember that shortest.Length with … Read more

[Solved] remove elemets from array where value of daughter array is equal [closed]

The easiest way to get the result you expect is in my opinion this way: $data = array( array( ‘domain’ => ‘messages’, ‘key’ => ‘test.testik’, ‘message’ => array() ), array( ‘domain’ => ‘messages’, ‘key’ => ‘test2313.tes31231tik’, ‘message’ => array() ), array( ‘domain’ => ‘validators’, ‘key’ => ‘valid.validik’, ‘message’ => array() ), array( ‘domain’ => ‘validators’, … Read more

[Solved] Need to implement an algorithm to obtain the average value of the fields of the graph structure( graph tree)

You could create recursive function with for…in loop and first calculate total sum and total number of nodes and then use those 2 values to calculate average. var graph_structure = {“val”:74,”child”:[{“val”:17,”child”:[{“val”:34,”child”:[{“val”:34,”child”:[{“val”:65,”child”:[{“val”:28,”child”:[{“val”:85},{“val”:30,”child”:[{“val”:68},{“val”:10,”child”:[{“val”:100,”child”:[{“val”:21,”child”:[{“val”:21},{“val”:64}]},{“val”:86}]}]}]}]}]},{“val”:22,”child”:[{“val”:17,”child”:[{“val”:65}]}]}]},{“val”:53,”child”:[{“val”:3,”child”:[{“val”:98,”child”:[{“val”:90,”child”:[{“val”:76,”child”:[{“val”:87,”child”:[{“val”:52,”child”:[{“val”:56}]}]},{“val”:47},{“val”:40,”child”:[{“val”:80,”child”:[{“val”:34}]},{“val”:23,”child”:[{“val”:47},{“val”:92}]},{“val”:98,”child”:[{“val”:89},{“val”:16},{“val”:10}]}]}]}]},{“val”:35,”child”:[{“val”:89,”child”:[{“val”:76,”child”:[{“val”:50,”child”:[{“val”:51},{“val”:90}]},{“val”:69,”child”:[{“val”:93},{“val”:98},{“val”:62}]}]}]}]}]}]}]}]}]},{“val”:98,”child”:[{“val”:85},{“val”:85,”child”:[{“val”:58,”child”:[{“val”:81,”child”:[{“val”:36,”child”:[{“val”:45,”child”:[{“val”:96,”child”:[{“val”:15,”child”:[{“val”:11,”child”:[{“val”:96}]}]},{“val”:48,”child”:[{“val”:4,”child”:[{“val”:74},{“val”:1}]},{“val”:7}]}]},{“val”:84,”child”:[{“val”:9},{“val”:81,”child”:[{“val”:10,”child”:[{“val”:67}]}]}]}]},{“val”:85,”child”:[{“val”:53},{“val”:7,”child”:[{“val”:47,”child”:[{“val”:74,”child”:[{“val”:30},{“val”:7},{“val”:12}]},{“val”:22}]},{“val”:56,”child”:[{“val”:51,”child”:[{“val”:45}]},{“val”:54,”child”:[{“val”:20},{“val”:62}]}]}]}]}]}]}]},{“val”:62,”child”:[{“val”:36,”child”:[{“val”:39,”child”:[{“val”:20}]},{“val”:10,”child”:[{“val”:91,”child”:[{“val”:81,”child”:[{“val”:59,”child”:[{“val”:19,”child”:[{“val”:59},{“val”:16}]},{“val”:35,”child”:[{“val”:30}]},{“val”:6,”child”:[{“val”:27}]}]},{“val”:89,”child”:[{“val”:60,”child”:[{“val”:59}]}]}]}]}]}]}]}]}]},{“val”:8,”child”:[{“val”:56,”child”:[{“val”:55,”child”:[{“val”:41,”child”:[{“val”:17,”child”:[{“val”:15,”child”:[{“val”:40,”child”:[{“val”:55,”child”:[{“val”:50},{“val”:99,”child”:[{“val”:86},{“val”:90}]}]}]},{“val”:85,”child”:[{“val”:36,”child”:[{“val”:39,”child”:[{“val”:45}]}]}]},{“val”:78,”child”:[{“val”:24,”child”:[{“val”:93,”child”:[{“val”:8}]},{“val”:26,”child”:[{“val”:5}]}]},{“val”:36}]}]},{“val”:13}]}]},{“val”:10,”child”:[{“val”:0,”child”:[{“val”:77,”child”:[{“val”:46,”child”:[{“val”:72,”child”:[{“val”:17,”child”:[{“val”:10},{“val”:67}]},{“val”:48},{“val”:60}]},{“val”:98,”child”:[{“val”:12,”child”:[{“val”:61},{“val”:27}]}]}]}]}]}]}]}]}]}]} function calc(data) { return (function repeat(data, res) { for(let i in data) { if(data.val) { res.nodes++; res.total += data.val if(!res.min) res.min = data else … Read more

[Solved] more than one type in Arraylist

This is not the proper way, but you can do something like this, ArrayList<Object> objects = new ArrayList<>(); objects.add(1); objects.add(“asd”); The better way is to create a different class with the attributes with Strings and int values you want. Then create an array with the type of that class and add those objects to the … Read more